<P>How does one go about decoding the output of forms? </P>
<P>If you are unfamiliar with forms or how to write them, we suggest you look at this <A HREF="http://www.ncsa.uiuc.edu/SDG/Software/Mosaic/Docs/fill-out-forms/overview.html">guide to fill-out
forms</A>. </P>
<P></P>
<HR>
<P></P>
<H2>Where do I get the form data from?</H2>
<P>As you now know, there are two methods which can be used to access your forms. These
methods are <CODE>GET</CODE> and <CODE>POST</CODE>. Depending on which method you used, you will recieve the
encoded results of the form in a different way. </P>
<P></P>
<UL>
<LI>The GET method <P>If your form has METHOD="GET" in its FORM tag, your CGI program will recieve the
encoded form input in the environment variable <CODE>QUERY_STRING</CODE>. </P>
<P></P>
</LI>
<LI>The POST method <P>If your form has METHOD="POST" in its FORM tag, your CGI program will recieve 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. </P>
<P></P>
</LI>
</UL>
<HR>
<H2>But what does it all mean? How do I decode the form
data?</H2>
<P>When you write a form, each of your input items has a NAME tag. When the user places data in
these items in the form, that information is encoded into the form data. The value each of the
input items is given by the user is called the value.</P>
<P>Form data is a stream of name=value pairs separated by the & character. Each name=value pair
is <A HREF="http://www.ncsa.uiuc.edu/demoweb/url-primer.html">URL</A> encoded, i.e. spaces are changed into spaces and some characters are encoded into
hexadecimal. </P>
<P>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 following are links into the CGI archive,
clicking on them will retrieve the software package being referred to.</P>
<P></P>
<UL>
<LI>The Bourne Shell: <A HREF="ftp://ftp.ncsa.uiuc.edu/Web/ncsa_httpd/cgi/AA-1.2.tar.Z">The AA archie gateway.</A> Contains calls to sed and awk which convert
a GET form data string into separate environment variables.<P></P>
</LI>
<LI>C: <A HREF="ftp://ftp.ncsa.uiuc.edu/Web/ncsa_httpd/cgi/ncsa-default.tar.Z">The default scripts for NCSA httpd.</A> While I won't win any awards for verbosity in
documenting my code, there are C routines and example programs you can use to
translate the query string into a group of structures.<P></P>
</LI>
<LI>PERL: <A HREF="ftp://ftp.ncsa.uiuc.edu/Web/ncsa_httpd/cgi/cgi-lib.pl.Z">The PERL CGI-lib.</A> This package contains a group of useful PERL routines to
decode forms. <P></P>
</LI>
<LI>TCL: <A HREF="ftp://ftp.ncsa.uiuc.edu/Web/ncsa_httpd/cgi/tcl-proc-args.tar.Z">TCL argument processor.</A> This is a set of TCL routines to retrieve form data and
place it into TCL variables. <P></P>
</LI>
</UL>
<P>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. </P>
<P><A HREF="overview.htm"><IMG SRC="../../images/back.gif" ALIGN=bottom BORDER=2 WIDTH=40 HEIGHT=40> Return to the overview</A> </P>
<P></P>
<HR>
<P>Copyright (C) 1995 Vermeer Technologies, Inc. All rights reserved. </P>