Read everything before doing anything.
Write a CGI script that validates the input in the form which you can see (and try out) at this linked page. You must use this file as your base HTML file.
Here are the requirements for your validation.
ten), and it must be
in the specified range (1 to 100). It may have
leading and trailing blanks.When you click the “Send Data” button, your script will validate the form data. If there are any errors, they must all appear in the resultant output. area. If there are no errors, you will echo back the data in any form that you feel appropriate.
In your error output, you must distinguish between:
You must use CGI; to extract the information from
the form.
You must use regular expressions in your validation code, though you don’t need to use it for every single conditon.
You may see what the finished program should do. (Try entering bad data to see how it responds.)
validator.cgi.print
statements with an occasional “here” document.@error_listpush @error_list, "your error message"
When you finish doing all your tests of all the input fields, look at the
size of @error_list. If there are no items in the array, you have
no errors, so you give the feedback of all the information. If there
are any items in the array, do code like this:
print "<ul>\n"; # start a bulleted list
foreach $item (@error_list)
{
print "<li>$item</li>\n";
}
print "</ul>\n"; # end bulleted list
Use the following code to remove leading and trailing blanks from a string:
sub trim
{
my $str = shift @_; # do you know why this works?!
# trim leading blanks by replacing one or more
# blanks at the start of the string with nothing.
$str =~ s/^\s+//;
# trim trailing blanks by replacing one or more
# blanks at the end of the string with nothing.
$str =~ s/\s+$//;
return $str;
}