GET and POST.
Depending on which method you used, you will receive the encoded
results of the form in a different way.
If your form has METHOD="GET" in its FORM tag, your CGI program
receives the encoded form input in the environment variable
QUERY_STRING.
If your form has METHOD="POST" in its FORM tag, your CGI program
receives the encoded form input on stdin. The server will NOT
send you an EOF on the end of the data, instead you should use the
environment variable CONTENT_LENGTH to determine how much
data you should read from stdin.
Form data is a stream of name=value pairs separated by the &
character. Each name=value pair is URL-encoded,
i.e. spaces are changed into plusses and some characters are
encoded into hexadecimal. Keywords are separated with the + plus.
Because others have been presented with this problem as well, there
are already a number of programs which will do this decoding for you.
The basic procedure is to split the data by the ampersands. Then, for
each name=value pair you get for this, you should URL
decode the name, and then the value, and then do what you like with them.
For example, the date and time routine is invoked using the statement
<!--#exec cgi="/cgi-bin/dater.cgi"-->
The routine to be invoked is named "dater.cgi", and resides in
the cgi-bin directory of the server. The actual location and name
is very server dependent.
When the routine is invoked, the server executes it. Depending on what the routine does determines what happens. In this case, the routine is a UNIX shell script that calls the system time and date routine then sends that information back to the browser in the appropriate format - meaning HTML statements.
To give you an example, here's the script for dater.cgi:
#!/bin/sh
echo ""
date +"%a %b %e, %Y"
echo ""
All this routine does is invoke the UNIX date routine
and returns the information in a specific format. The echo
command means to display on the screen EXACTLY what is contained on the
rest of the line. In other words, display a blank line. The requirement
of this approach is the need to work with UNIX shell commands. Many
providers do not allow users to develop CGI routines. Most provide a
small group of "canned" CGI routines, such as the collection at BPL.
To invoke the system environment routine vars.cgi,
a PERL script is used:
#!/usr/bin/perl
print "Content-type: text/html\n\n";
$ss = $ENV{"SERVER_SOFTWARE"};
$sn = $ENV{"SERVER_NAME"};
$su = $ENV{"SERVER_URL"};
$gi = $ENV{"GATEWAY_INTERFACE"};
$rm = $ENV{"REQUEST_METHOD"};
$sp = $ENV{"SERVER_PORT"};
$rh = $ENV{"REMOTE_HOST"};
$ra = $ENV{"REMOTE_ADDR"};
$ru = $ENV{"REMOTE_USER"};
$ua = $ENV{"HTTP_USER_AGENT"};
$hf = $ENV{"HTTP_FROM"};
$sc = $ENV{"SERVER_PROTOCOL"};
$path = $ENV{"PATH_INFO"};
$qu = $ENV{"QUERY_STRING"};
$sm = $ENV{"SCRIPT_NAME"};
$ht = $ENV{"HTTPS"};
$hk = $ENV{"HTTPS_KEYSIZE"};
print "<br>Server Software: ".$ss."\n";
print "<br>Server Name : ".$sn."\n";
print "<br>Server URL : ".$su."\n";
print "<br>Gateway I/F : ".$gi."\n";
print "<br>Request Method : ".$rm."\n";
print "<br>Server Port : ".$sp."\n";
print "<br>Remote Host : ".$rh."\n";
print "<br>Remote Address : ".$ra."\n";
print "<br>Remote User : ".$ru."\n";
print "<br>User Agent : ".$ua."\n";
print "<br>Email from : ".$hf."\n";
print "<br>Server protocol: ".$sc."\n";
print "<br>Path Info : ".$path."\n";
print "<br>Query String : ".$qu."\n";
print "<br>Script Name : ".$sm."\n";
print "<br>Security? : ".$ht."\n";
print "<br>Keysize : ".$hk."\n";
1;
Note that the line
print "Content-type: text/html\n\n";
is required to tell the web browser that the information returned is
plain text. The rest of the statements are PERL commands that get the
specific information from the $ENV or system environment table, and
formats it (using the print statements) into HTML statements.
Again, the need to know not only the UNIX system but also the PERL language.
The POST is useful for
Any HTML editor (HotDog, PageMill, etc) support the basic design of the layout - the fields, actions, defaults and so on.
In the SIGGRAPH example, the FORM tag is
<form method=POST action="mailto:xxxxx@acm.org">I'm sending information to the server using a POST command, and the server program I want invoked is the "mailto". All the information from the form will be packaged into a mail message to me at
xxxxx@acm.org. The form begins with the
<FORM> command and ends at the </FORM> command.
name,
street, city, state, zip, email and fax are
the names of the specific text fields.
TEXTAREA can be used. By defining
the number of rows and columns, the free-form area is created on the
page.
Any other comments, questions, requests, etc?
<br><textarea name="comment" rows=8 cols=60></textarea>
Are you currently a member of ACM?
<input type="radio" name="acm" value="Yes" checked>Yes
<input type="radio" name="acm" value="No">No
In this example, the set of radio buttons is named "acm" and
the value of each is set. Another attribute is checked.
By setting this attribute, that value is the default unless
changed by the user.
Are you currently a member of the following? [Please check all that apply] <br><input type="checkbox" name="other" value="IEEE">IEEE <br><input type="checkbox" name="other" value="HFA">Human Factors Association <br><input type="checkbox" name="other" value="NCGA">NCGA <br><input type="checkbox" name="other" value="CLA">CLA
SIZE command notes that 5 items are to be displayed.
What is the closest ACM Chapter or other ACM Local SIG to you?In order to save space on the form and to show only that information needed at any specific time, the PopUp menu works fine. The PopUp Menu is the same, but the SIZE is only 1, hence the need to display the information in a "hot menu".
<select name="chapter" size="5"> <option>Denver <option>Boulder <option>Ft Collins <option>Colorado Springs <option>none </select>
SUBMIT
and RESET.
<input type="submit" value="Send">
<input type="reset" value="Don't Send">