|
|
||||||||||||
|
|
Advanced Methods | CGI and Forms |
|
|
|
||||||||
|
CGI and Forms
Let's now take a look at a very common use of CGI scripts, processing user
input supplied in forms. We'll consider examples of both C
and Perl programs
applied to the problem.
A Very Simple Example
Note that we have two things working together in this example. First, text is entered in the form; second, the text is passed on to a program that "processes" this information. In the present case the processing is rather trivial: the information is simply echoed back to the client. But the CGI script can be designed to do much more than this with the information; we'll look at such an example in a little while.
The FORM Tag
The program that processes the information entered into this form, however,
is not HTML. In this case, the processing is done by a compiled
C
program named post-query
that resides in the cgi-bin subdirectory of the
directory holding the server software on a computer with IP address
csep10.phys.utk.edu.
Note that the form uses the value assigned to "ACTION=" in the tag to tell
the server what program it should use to
process the information that is being sent from the
form.
More Information on Constructing Forms
More Complex Examples
An example of a more complicated form (and more complicated processing of form data) is an online science quiz. A similar example at the same site features a form that provides a quiz in astronomy. If you go to the page with the science quiz and use your browser to view the document source, you'll note the line:
From this we see that the information entered into this form is processed by a program called qa.pl (on the same machine as the form, which is why you don't see an http-type url assigned to action= in this case).
This program is a Perl
script that has been written specifically to handle the information submitted
by this one form. Rather than simply echoing entered text as
post-query does,
qa.pl examines the
submitted information, extracts the part that corresponds to the answer
to the question, compares this to the correct answer for the question (which is
stored in a database on the server), and then
presents the user with one of various possible pages depending on whether or not
the correct answer to the question was entered. This illustrates that
a gateway script can do much more than simply echo arbitrary text. If you are
interested, here is a listing of the
Perl program qa.pl.
|
||||||||||||
|
|
||||||||||||