#!/usr/bin/perl
use CGI;
$cgi = new CGI;
for $key ( $cgi->param() ) {
$input{$key} = $cgi->param($key);
}
print qq(Content-type: text/html\n\n);
if ( $input{name} ) {
$new_html = qq(<p><blockquote><font color="red">);
$new_html .= qq(You are $input{name}\n);
$new_html .= qq(<p>You wish to be a $input{animal}\n);
$new_html .= qq(<p>You pushed the $input{request} button);
$new_html .= qq(</font></blockquote>\n<p>);
open HTML, "course/cgi_module/form_errors.html";
while ( <HTML> ) {
s/<!-- example3substitution -->/$new_html/;
print;
}
close HTML;
} else {
open HTML, "course/cgi_module/example3.html";
while ( <HTML> ) {
# add an explanation
s{<body>}{<body><p><font color="red">
Put in your name or be a ding-bat</font><p>};
#restore the selected option
s{<option value="$input{animal}"}
{<option value="$input{animal}" selected};
print;
}
close HTML;
}