CGI
The Perl script CGI snippet does the same thing as the JavaScript. It checks to see if the required fields are there, and if not, saves an error message into a variable for display:
#!/usr/local/bin/perl
$error = "";
if ($in{'dd'} eq "")
{
$error += "Please select from the drop down box.<p>";
}
if ($in{'words'} eq "")
{
$error += "Please include some words in the text box.<p>";
}
...
if ($error)
{
print "Content-type: text/html \n\n";
print "<html><head><title>Error</title>";
print "</head><body>";
print "<h2>An Error Has Occurred</h2>";
print $error ;
print "Please go back and correct these errors.";
print "</body></html>";
} else {
Go on with the CGI ...
}
The difference with how the CGI writes the error message is that instead of a "\n", it uses the HTML code <p> to put a new line in between each error.
And Now You've Validated Your Form
With the two methods, CGI and JavaScript, you've validated an HTML form so that more of the parts that are sent to you are accurate.

