HP e3000 Web Server CGI Programming (November 2008)
<HTML>
<HEAD> <TITLE> Phone Book </TITLE></HEAD>
<BODY>
<H1> Phone Book </H1>
<HR>
<FORM ACTION=http://hozone.cup.hp.com/cgi-bin/phonebook METHOD=POST>
<PRE>
Name : <INPUT TYPE="text" NAME=name SIZE=40 MAXLENGTH=40> <p>
Phone : <INPUT TYPE="text" NAME=number SIZE=10 MAXLENGTH=10> <p>
</PRE>
<INPUT TYPE="submit" NAME=ACTION VALUE=ADD>
<INPUT TYPE="submit" NAME=ACTION VALUE=DELETE>
<INPUT TYPE="submit" NAME=ACTION VALUE=SEARCH>
<INPUT TYPE="reset" VALUE=CLEAR>
</FORM>
<HR>
</BODY>
</HTML>
The application works as follows:
The ADD button allows you to add the name and number to the phonebook.
The DELETE button deletes the phonebook entry corresponding to the name entered in the name
field.
The SEARCH allows you to search the phonebook using names.
The form used here is very simple, containing only two text input fields: one for the name and the
other for the phone number. When the user types in the required information and clicks one of the
ADD/DELETE/SEARCH buttons, the form data is submitted to the CGI program on the webserver.
The URL of the CGI program appears to the right of the "ACTION=" argument in the FORM tag in the
HTML form. In the form shown above this is http://hozone.cup.hp.com/cgi-bin/phonebook. The form
data is submitted in an encoded form which has to be decoded by the CGI program.
The browser encodes the form information in a special way so that the CGI program at the web
server can re-extract the individual fields in an easy manner. The encoding process is very simple,
the browser just appends all the individual fields in the format "name=value", separated by
"&" (ampersand) signs. Here "name" is the name of the field as specified in the HTML form and
"value" is the data that the user typed into the field. Spaces are replaced with "+" (plus) signs; Special
characters are replaced by the hex value prefixed with the % (percent) sign. Refer to the IETF RFC
1738 <http://www.ics.uci.edu/pub/ietf/uri/ rfc1738.txt > to learn more about these encodings. The
process of re-extracting the individual fields of the form is commonly referred to as "parsing the CGI
input".
To illustrate this encoding with an example, consider the following form:
Page
5
of
10
HP e3000 Web Server CGI Programming
11/13/2008
http://www.hp.com/cgi
-
bin/pf
-
new.cgi?IN=http://jazz.external.hp.com/papers/cgi
-
paper/c
...