home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Internet Business Development Kit / PRODUCT_CD.iso / ftpage / disk6 / forms0.ht_ / forms0.ht
Encoding:
Text File  |  1995-09-07  |  3.6 KB  |  73 lines

  1. <!DOCTYPE HTML PUBLIC "-//W3O//DTD W3 HTML 2.0//EN">
  2.  
  3. <HTML>
  4.  
  5. <HEAD>
  6. <TITLE>The Common Gateway Interface: FORMS</TITLE>
  7. <META NAME="GENERATOR" CONTENT="Vermeer FrontPage 1.0">
  8. </HEAD>
  9.  
  10. <BODY>
  11. <H1>Supporting FORMS with CGI</H1>
  12. <P>How does one go about decoding the output of forms? </P>
  13. <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 
  14. forms</A>. </P>
  15. <P></P>
  16. <HR>
  17. <P></P>
  18. <H2>Where do I get the form data from?</H2>
  19. <P>As you now know, there are two methods which can be used to access your forms. These 
  20. methods are <CODE>GET</CODE> and <CODE>POST</CODE>. Depending on which method you used, you will recieve the 
  21. encoded results of the form in a different way. </P>
  22. <P></P>
  23. <UL>
  24. <LI>The GET method <P>If your form has METHOD="GET" in its FORM tag, your CGI program will recieve the 
  25. encoded form input in the environment variable <CODE>QUERY_STRING</CODE>. </P>
  26. <P></P>
  27. </LI>
  28. <LI>The POST method <P>If your form has METHOD="POST" in its FORM tag, your CGI program will recieve the 
  29. encoded form input on stdin. The server will NOT send you an EOF on the end of the 
  30. data, instead you should use the environment variable CONTENT_LENGTH to 
  31. determine how much data you should read from stdin. </P>
  32. <P></P>
  33. </LI>
  34. </UL>
  35. <HR>
  36. <H2>But what does it all mean? How do I decode the form 
  37. data?</H2>
  38. <P>When you write a form, each of your input items has a NAME tag. When the user places data in 
  39. these items in the form, that information is encoded into the form data. The value each of the 
  40. input items is given by the user is called the value.</P>
  41. <P>Form data is a stream of name=value pairs separated by the & character. Each name=value pair 
  42. 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 
  43. hexadecimal. </P>
  44. <P>Because others have been presented with this problem as well, there are already a number of 
  45. programs which will do this decoding for you. The following are links into the CGI archive, 
  46. clicking on them will retrieve the software package being referred to.</P>
  47. <P></P>
  48. <UL>
  49. <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 
  50. a GET form data string into separate environment variables.<P></P>
  51. </LI>
  52. <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 
  53. documenting my code, there are C routines and example programs you can use to 
  54. translate the query string into a group of structures.<P></P>
  55. </LI>
  56. <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 
  57. decode forms. <P></P>
  58. </LI>
  59. <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 
  60. place it into TCL variables. <P></P>
  61. </LI>
  62. </UL>
  63. <P>The basic procedure is to split the data by the ampersands. Then, for each name=value pair you 
  64. get for this, you should URL decode the name, and then the value, and then do what you like 
  65. with them. </P>
  66. <P><A HREF="overview.htm"><IMG SRC="../../images/back.gif" ALIGN=bottom BORDER=2 WIDTH=40 HEIGHT=40> Return to the overview</A> </P>
  67. <P></P>
  68. <HR>
  69. <P>Copyright (C) 1995 Vermeer Technologies, Inc. All rights reserved. </P>
  70. </BODY>
  71.  
  72. </HTML>
  73.