• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Sending data in cgi
 

Sending data in cgi

on

  • 17,774 views

 

Statistics

Views

Total Views
17,774
Views on SlideShare
17,766
Embed Views
8

Actions

Likes
0
Downloads
3
Comments
0

1 Embed 8

http://blackboard.chaffey.edu 8

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Sending data in cgi Sending data in cgi Presentation Transcript

    • Sending Data Using an Online Form CISIWEB 430A
    • Objectives
      • In this unit, you will
        • Plan and create a CGI script that processes form data
        • Learn how to prevent Perl from creating undeclared variables in a script
        • Declare (create) scalar variables in a script
        • Use assignment statements to assign values to existing variables
        • Send form data to a script using GET and POST
        • Improve the appearance of numbers displayed on a Web page
    • <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;;
    • Planning the script
      • Plan the HTML page
      • Plan the logic for the script
      • Plan the information the script will output
    • Accessing Form Data
      • In an HTML form, the keys are the names of the form elements, and the values are the information (usually) entered by a user.
      • When the user presses the “Submit” button, the data are automatically transmitted to the script.
      • Once the data are sent, our script needs to parse the data so that we can use it.
        • If we use the CGI.pm module, parsing the data from a form is identical to parsing the data from a hyperlink.
    • Creating the Form
      • Use HTML to create the form
        • FORM tag contains instructions
          • Action = location of .cgi
          • Method = Get or Post
          • Submit – calls the action to happen
          • Controls – include a name attribute
    • Get vs. Post
        • 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
        • POST sends the data as a separate data stream, allowing the Web server to receive the data through “STANDARD INPUT”
    • Including special characters
      • This project uses a dollar sign, which can’t be typed in directly (why not?)
      • Characters that are given special meaning within a regular expression
      • Backslash if you want to use literally
        • :. * ? + [ ] ( ) { } ^ $ |
        • Any other characters automatically assume their literal meanings.
    • Using printf
      • Printf function is used for displaying data on a Web page
        • Allows you to format the information
        • Allows you to specify the number of decimal places
        • Allows you to display a + or – before the number
        • Syntax: printf formatstring, list;
          • List is a comma separated list of items
          • Formatstring contains text and one or more format fields
    • Parts of a format field
          • % - required, at the beginning of a format field
          • Modifier – optional (+ or – to denote a positive or negative number)
          • Minimum field width – option, sets a min number of characters to display
          • Precision – optoin, expressed as a period followed by a number, the number of digits to the right of the decimal
          • Format type – required – d (decimal) or f (floating point)