In this thirteenth slide, we introduce the CGI program processing a survey
form.
We store the variable pairs in an associative array:
foreach $ii (sort $query->param())
{
$jj=$query->param($ii);
$qx{$ii}=$jj;
}
We then display the variable pairs
foreach $key (keys %qx)
{
$val=$qx{$key};
print "${key}: ${val}<br>";
}
1. THE CGI PROGRAM:
#!/usr/local/bin/perl
use CGI qw(:standard);
$query=new CGI;
print $query->header;
foreach $ii (sort $query->param())
{
$jj=$query->param($ii);
$qx{$ii}=$jj;
}
print "<html><head><title>Form Parameters</title></head>\n";
print "<body>";
print "<h1>Form Parameters<h1>\n";
if (%qx)
{
foreach $key (keys %qx)
{
$val=$qx{$key};
print "${key}: ${val}<br>";
}
}
else
{
print "No form was submitted<br>";
}
print "</body></html>";
2. PROGRAM DESCRIPTION:
The first three lines are identical as slide #10
The next five lines read the Evaiable pairs into the associative array.
foreach $ii (sort $query->param())
{
$jj=$query->param($ii);
$qx{$ii}=$jj;
}
The next 3 lines print the document header
The next 5 lines print the information entered on the form, if any:
foreach $key (keys %qx)
{
$val=$qx{$key};
print "${key}: ${val}<br>";
}
if not, we print: "No form was submitted<br>";
The last line close the form, the paragraph, the body and the html tag.
|