Sending data in cgi

40,202 views
40,083 views

Published on

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
40,202
On SlideShare
0
From Embeds
0
Number of Embeds
10
Actions
Shares
0
Downloads
7
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Sending data in cgi

  1. 1. Sending Data Using an Online Form CISIWEB 430A
  2. 2. Objectives <ul><li>In this unit, you will </li></ul><ul><ul><li>Plan and create a CGI script that processes form data </li></ul></ul><ul><ul><li>Learn how to prevent Perl from creating undeclared variables in a script </li></ul></ul><ul><ul><li>Declare (create) scalar variables in a script </li></ul></ul><ul><ul><li>Use assignment statements to assign values to existing variables </li></ul></ul><ul><ul><li>Send form data to a script using GET and POST </li></ul></ul><ul><ul><li>Improve the appearance of numbers displayed on a Web page </li></ul></ul>
  3. 3. <html> <head> <title>Chapter 3 - Parsing Data</title> </head> <body bgcolor=&quot;#FFFFFF&quot;> <form action=&quot;http://myServer/parse2.cgi&quot; METHOD=POST> Comment <input type=&quot;text&quot; name=&quot;myComment&quot;> <p> <input TYPE = &quot;submit&quot; value = &quot;Submit&quot;> <input TYPE = &quot;reset&quot; VALUE = &quot;Start Over&quot;> </p> </form> </body> </html> #!/usr/bin/perl use CGI qw(:standard); print &quot;Content-type: text/html &quot;; print &quot;<HTML><HEAD><TITLE>Chapter 3&quot;; print &quot; - Output</TITLE></HEAD><BODY> &quot;; print param('myComment'); print &quot;</BODY></HTML>&quot;;
  4. 4. Planning the script <ul><li>Plan the HTML page </li></ul><ul><li>Plan the logic for the script </li></ul><ul><li>Plan the information the script will output </li></ul>
  5. 5. Accessing Form Data <ul><li>In an HTML form, the keys are the names of the form elements, and the values are the information (usually) entered by a user. </li></ul><ul><li>When the user presses the “Submit” button, the data are automatically transmitted to the script. </li></ul><ul><li>Once the data are sent, our script needs to parse the data so that we can use it. </li></ul><ul><ul><li>If we use the CGI.pm module, parsing the data from a form is identical to parsing the data from a hyperlink. </li></ul></ul>
  6. 6. Creating the Form <ul><li>Use HTML to create the form </li></ul><ul><ul><li>FORM tag contains instructions </li></ul></ul><ul><ul><ul><li>Action = location of .cgi </li></ul></ul></ul><ul><ul><ul><li>Method = Get or Post </li></ul></ul></ul><ul><ul><ul><li>Submit – calls the action to happen </li></ul></ul></ul><ul><ul><ul><li>Controls – include a name attribute </li></ul></ul></ul>
  7. 7. Get vs. Post <ul><ul><li>GET appends the form data to the end of the URL specified in the action property and is similar to sending the data through a hyperlink </li></ul></ul><ul><ul><li>POST sends the data as a separate data stream, allowing the Web server to receive the data through “STANDARD INPUT” </li></ul></ul>
  8. 8. Including special characters <ul><li>This project uses a dollar sign, which can’t be typed in directly (why not?) </li></ul><ul><li>Characters that are given special meaning within a regular expression </li></ul><ul><li>Backslash if you want to use literally </li></ul><ul><ul><li>:. * ? + [ ] ( ) { } ^ $ | </li></ul></ul><ul><ul><li>Any other characters automatically assume their literal meanings. </li></ul></ul>
  9. 9. Using printf <ul><li>Printf function is used for displaying data on a Web page </li></ul><ul><ul><li>Allows you to format the information </li></ul></ul><ul><ul><li>Allows you to specify the number of decimal places </li></ul></ul><ul><ul><li>Allows you to display a + or – before the number </li></ul></ul><ul><ul><li>Syntax: printf formatstring, list; </li></ul></ul><ul><ul><ul><li>List is a comma separated list of items </li></ul></ul></ul><ul><ul><ul><li>Formatstring contains text and one or more format fields </li></ul></ul></ul>
  10. 10. Parts of a format field <ul><ul><ul><li>% - required, at the beginning of a format field </li></ul></ul></ul><ul><ul><ul><li>Modifier – optional (+ or – to denote a positive or negative number) </li></ul></ul></ul><ul><ul><ul><li>Minimum field width – option, sets a min number of characters to display </li></ul></ul></ul><ul><ul><ul><li>Precision – optoin, expressed as a period followed by a number, the number of digits to the right of the decimal </li></ul></ul></ul><ul><ul><ul><li>Format type – required – d (decimal) or f (floating point) </li></ul></ul></ul>

×