home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / C / Applications / Moscow ML 1.42 / examples / cgi / README1 < prev    next >
Encoding:
Text File  |  1997-08-18  |  2.7 KB  |  74 lines  |  [TEXT/R*ch]

  1. Example 1: A simple HTML form and a CGI program in Moscow ML
  2. ------------------------------------------------------------
  3.  
  4. An HTML form has an associated action, which is usually a call to a
  5. CGI program, such as 
  6.     ACTION="http://www.dina.kvl.dk/cgi-bin/sestoft/cgiex1"
  7.  
  8. When the user submits the form, the webbrowser will send a request to
  9. the indicated webserver (www.dina.kvl.dk).  The server will invoke the
  10. CGI program WWWSERVERPREFIX/cgi-bin/sestoft/cgiex1 to handle the
  11. request (the WWWSERVERPREFIX is an installation-specific path;
  12. typically /var/lib/httpd).
  13.  
  14.  
  15. To send a form from the client (browser) to a WWW server, and make the
  16. server respond properly, you need to write the following components:
  17.  
  18.     (A) An HTML page containing a FORM
  19.     (B) A CGI program to receive the form, process it, and respond
  20.   
  21. (A) You need an HTML page containing a FORM.  The FORM must have
  22.  
  23.     - METHOD="POST" 
  24.     - an ACTION equalling the URL of a CGI program
  25.     - any number of named INPUT, SELECT, or TEXTAREA fields
  26.     - one or more INPUT fields with TYPE=SUBMIT
  27.  
  28. See file `htmlform.html' for an example HTML form.  With that form,
  29. you can type in a text in a TEXTAREA (on the system running the
  30. browser) and choose whether you want to count the number of characters
  31. in the textarea, count the number of lines in the textarea, or sort
  32. the lines of the textarea.
  33.  
  34. Note that in htmlform.html, the textarea is named "texttoprocess" and
  35. the select menu is named "action".
  36.  
  37. (B) You need a CGI program
  38.  
  39. See file `cgiex1.sml' for an example CGI program.  That program will
  40. handle requests sent from the above-mentioned example form.  Within
  41. the example CGI program, the contents of the HTML form's textarea is
  42. retrieved as
  43.     Mosmlcgi.cgi_field_string "texttoprocess"
  44. and the chosen select menu option is retrieved as
  45.     Mosmlcgi.cgi_field_string "action"
  46.  
  47.  
  48. INSTRUCTIONS FOR USE
  49.  
  50. (1) Edit the FORM in file `htmlform.html' so that ACTION refers to a
  51. cgi-bin directory on your local webserver.
  52.  
  53. (2) Compile the CGI program:
  54.  
  55.    mosmlc -c cgiex1.sml
  56.    mosmlc -o cgiex1 cgiex1.uo
  57.  
  58. (3) Install the compiled CGI program on your local webserver:
  59.  
  60.    cat `which camlrunm` cgiex1 > /var/lib/httpd/cgi-bin/sestoft/cgiex1
  61.    chmod a+x /var/lib/httpd/cgi-bin/sestoft/cgiex1
  62.  
  63. The above assumes that your webserver lives in /var/lib/httpd/ so that
  64. your CGI program directory is /var/lib/httpd/cgi-bin/sestoft/, and
  65. that you are allowed to install CGI programs on your webserver.
  66. Change the path as appropriate.  (Note that the runtime system is
  67. simply prepended to the ML bytecode, so that the webserver need not
  68. look for it.)
  69.  
  70. The included Makefile automates steps (2) and (3) above.
  71.  
  72. (4) Open the HTML file `htmlform.html' with your webbrowser, fill in
  73. the form, and click on `Send'.
  74.