separator

Take a quiz or make one of your own
Article 5 - CGI Form Handling with Perl
What are HTML forms and why use them?
Forms are a means for allowing a web site to interact with a user by collecting data. There are actually two common means that a webpage can communicate information back to a program running on the server. GET, and POST.
In this tutorial we'll be using the POST method, which puts the data entered on the form into a file which our program will read. The file is known as the 'standard input' file and the Perl filehandle 'STDIN' is preset to this file. All we need to specify is the length of the data, and that's contained in the Environment Variable $ENV{'CONTENT_LENGTH'}. Therefore the following will assign the contents of a POST operation to a variable inside our pgm:

read(STDIN, $namevals, $ENV{'CONTENT_LENGTH'});
The reason I chose to assign the standard input file data to a buffer called $namevals is because the information is pre- formatted in 'name value pairs'. Suppose for instance you had a form with two text fields in it, called 'name' and 'email'. And I visited your site and typed 'Marty Landman' and 'marty@thecgibin.com' in those fields, and then submitted the form. After executing the read statement above, the $namevals scalar variable would contain
'name=Marty Landman&email=marty@thecgibin.com'

Actually that's not quite accurate. But it's close enough for our current purposes.
Did someone say "Application"?
What are we going to use our form for? The form gives us a convenient way to gather information supplied by a visitor to our website, and the program it posts to gives us the means to work with that information. Now we just need something to apply all this to.

The NCSA HTTPd ErrorDocument Directive

The webpage from the link above talks about errors that can be raised on the server hosting a website. You've certainly seen some of them already in your travels. For instance when you incorrectly type in a URL for a page you get the '404 - NOT_FOUND' error message. When debugging a CGI program, you can get the '500 - SERVER_ERROR' message.
By putting an '.htaccess' file on you web directory all the files under that directory will be subject to the overrides specified in the .htaccess file. There are seven different error documents specified on the NCSA doc and what we'll do is customize all seven. And we'll use an HTML form and CGI form processing program to do it!

separator

© www.thecgibin.com