CGI FORM training - the code
The PERL Code
The following is a listing of the perl code which writes the new page.
#!/usr/bin/perl
######################
# Sample code for CGI interface testing
# Created 1/6/1997
# mod 6/1/1997
# Define Variables
# Print the Initial Output Heading
print "Content-type: text/html\n\n";
# Get the input
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
# Split the name-value pairs
@pairs = split(/&/, $buffer);
foreach $pair (@pairs)
{
($name, $value) = split(/=/, $pair);
# Un-Webify plus signs and %-encoding
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$name =~ tr/+/ /;
$name =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
# Stop people from using subshells to execute commands
# Not a big deal when using sendmail, but very important
# when using UCB mail (aka mailx).
# $value =~ s/~!/ ~!/g;
# Uncomment for debugging purposes
# print "Setting $name to $value<P>";
$FORM{$name} = $value;
}
# Print Return HTML
print "<html><head><title>$FORM{'titlebar'}</title></head>\n";
print "<body bgcolor=$FORM{'bgcolor'}>";
print "<font color=$FORM{'textcolor'}>";
print "\n";
print "<center>";
print "\n";
print "<h1>My first CGI interface page!</h1>";
print "\n";
print "<P>Today, $FORM{'day'}, $FORM{'yourname'} <br> -- affectionately\n";
print " known to my friends as $FORM{'nickname'} -- <br> \n";
print " wrote my first <b>FORM</b> on a Webpage!\n";
print "<P>Below is some of the information it contained.\n";
print "</center>";
print "\n";
print "<hr>";
print "<center>";
print "<font size=+2>Here are some of my friends</font>";
print "<br>";
if ($FORM{'woody'} eq "yes") {
print "\n<img src=../graphics/gif/woody.gif>\n";
print "<br>";
}
if ($FORM{'dianek'} eq "yes") {
print "\n<img src=../graphics/gif/dkeaton.gif>\n";
print "<br>";
}
if ($FORM{'bogart'} eq "yes") {
print "<img src=../graphics/gif/bogie.jpg>\n";
print "<br>";
}
if ($FORM{'marilyn'} eq "yes") {
print "<img src=../graphics/gif/mariliyn.jpg>\n";
print "<br>";
}
if ($FORM{'oprah'} eq "yes") {
print "<img src=../graphics/gif/oprah.jpg>\n";
print "<br>";
}
if ($FORM{'dannyg'} eq "yes") {
print "<img src=../graphics/gif/dannyg.jpg>\n";
print "<br>";
}
print "</center>";
print "<hr>";
print "<h2>Here's a little bit about me:</h2>\n";
print " <ul><li>my favorite color is $FORM{'mycolor'}\n";
$print_philosopher = " <li>my favorite philosopher is $FORM{'myphilosopher'}, \n";
$check_for_Rush = index($FORM{'myphilosopher'},"Rush");
if ($check_for_Rush > -1) {
$print_philosopher = " <li>the instructor says my favorite philosopher really isn\'t one...\n";
}
print $print_philosopher;
print " <li>my oldest child is $FORM{'oldest'}.\n";
print "</ul>";
print "<hr>";
print "<h2>I'm currently in $FORM{'currentcity'}</h2>\n";
print "And here is what I want the world to know about that town";
print "<p>";
print "<blockquote><blockquote>";
print "<i>$FORM{'comments'}</i>\n";
print "</blockquote></blockquote>";
print "<hr>";
print "<font size=+3><center> Good-bye!</font><br>Gosh this was fun!!!</center>";
print "<p>";
print "<center><font size=-1>HTML page generated by nation1.pl program</font></center>\n";
print "</font>";
print "</body></html>";