Tutorial 6: Working With Forms II
(The CGI)

 

 

The following tutorial presupposes that you have some familiarity with HTML authoring.
It does not teach you how to write a CGI script.
This is the script that handles the form in:
template5.html.
Go to
Tutorial5 to learn how to create the corresponding HTML document that contains the form.
Go to
template6.pl to see this script.

This tutorial further assumes that you have the permission to install CGI scripts on your web server, and that this server runs the UNIX operating system and makes the Perl programming language available to you. Your system administrator or webmaster should be able to help you with specific questions.

The example script has been tested and is known to work on the following system:

FreeBSD v2.2
Apache v1.2
Perl v5.003


Note:


Changes you need to make to the example CGI script:

  1. The very first line of the script specifies the path of the Perl programming language interpreter on the specific web server system we are using. In our case it reads:

    #!/usr/bin/perl

    An easy way to find out what should go into this line is to type

    which perl

    in your UNIX system's shell. The output of this commant should follow the # ! characters on the first line of the script. Also, your system administrator or webmaster should be able to tell you what goes in there.

  2. A similar procedure as the one in the previous part can be used to find where the program sendmail is located. The variable $mailprog should contain this information. In our case, we use a line that says:

    $mailprog = '/usr/sbin/sendmail';

  3. In the next block, we will specify the instructor's complete e-mail address. In our case, the address is jarana@leia.ursinus.edu, and the line reads:

    $teacher = ('jarana@leia.ursinus.edu');

  4. Next, we make sure that the user filled all the required blanks. We do that with a block of lines, each of which looks like this:

    blank_&response unless $FORM{'FieldName'};

    where FieldName are the names of all required fields in the HTML form. Each form element (pull-down menu, check box, etc.) that you want to be required needs to appear in one of these lines.

  5. Next, the most important part, we will generate the e-mail message that is sent to the instructor. We will have to modify all lines in this section starting with the Subject: line. You determine the content and the format of the message.


  6. Lastly, in the next block, we provide a feedback web page for the user. This is an HTML page generated by the script using the print statement (without the word MAIL), and may include the input submitted by the user in the same format as in the e-mail.
    To avoid any problems with quotes (
    " ), precede them with a backslash ( \ ).