CGI/PERL Tutorial over the Web

Click to go to the PREVIOUS page. Click to go to the INDEX page. Click to go to the NEXT page.

SLIDE #4 A CGI PROGRAM PROCESSING A FORM


In this fourth slide, we introduce the CGI program processing the form.

Remember that the CGI protocole treats data input in the form as variable pairs:
field name, field value. The CGI library has a method, called param, which
provides, for each field name, the value entered by the user. 
If for example, the user entered the value 25 in field named age, then the
statement:
if ($query->param('age') > 18)
will compare the value entered in the age field to 18, and return true or 
false based on the result of the comparison.

1. THE CGI PROGRAM:

#!/usr/local/bin/perl
use CGI;
$query=new CGI;
print $query->header;
print "<html><head><title>Are you old enough to vote?</title></head>\n";
print "<body>";
if ($query->param('age') > 18) 
{ 
	print "<p>You are old enough to vote.<p>\n";
}
else
{
	print "<p>You are not yet old enough to vote.<p>\n";
}
print "</body></html>";

2. PROGRAM DESCRIPTION:

The first four lines are identical as slide #2

The next two lines display the header and the body of the HTML form:

The next lines (7-14) check if we are old enough to vote and display the
relevant message.

Line 15 closes the body and html tags.


© Copyright 2002 International Customized Software Co.