sending data in cgi

10
Sending Data Using an Online Form CISIWEB 430A

Upload: chaffey-college

Post on 13-Dec-2014

36.106 views

Category:

Documents


1 download

DESCRIPTION

 

TRANSCRIPT

Page 1: Sending data in cgi

Sending Data Using an Online Form

CISIWEB 430A

Page 2: Sending data in cgi

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

Page 3: Sending data in cgi

<html><head><title>Chapter 3 - Parsing Data</title></head><body bgcolor="#FFFFFF"><form action="http://myServer/parse2.cgi" METHOD=POST>Comment <input type="text" name="myComment"><p><input TYPE = "submit" value = "Submit"><input TYPE = "reset" VALUE = "Start Over"></p></form></body></html>

#!/usr/bin/perluse CGI qw(:standard);print "Content-type: text/html\n\n";print "<HTML><HEAD><TITLE>Chapter 3";print " - Output</TITLE></HEAD><BODY>\n";print param('myComment');print "</BODY></HTML>";

Page 4: Sending data in cgi

Planning the script

Plan the HTML page Plan the logic for the script Plan the information the script will

output

Page 5: Sending data in cgi

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.

Page 6: Sending data in cgi

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

Page 7: Sending data in cgi

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”

Page 8: Sending data in cgi

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.

Page 9: Sending data in cgi

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

Page 10: Sending data in cgi

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)