Simple Form Processing

Forms provide the best method for gathering data from your customers. This tutorial will help you learn how to set up a simple form. The steps below will illustrate how it is done.

  1. Make the HTML page
    First create the HTML for the web page that will be used to collect the data. Here is a sample for your use.

    <html>
    <head>
    <title>My First Form</title>
    </head>
    <body>
    <h3>Information</h3>
    <hr>
    <br><br>
    Thank you for your inquiry about our company and our services.
    To help us better answer your questions, we have prepared this
    form.  Please enter in your name, email address, the subject,
    and your question or inquiry below. 
    <br><br>
    <hr>
    
    <form method="POST" action="/cgi-bin/comments.pl">
    <input name="recipient" type="hidden" value="info@MY_COMPANY.com">
    <font size="+1">Your Full Name:</font><br>
    <input name="name" size=50>
    <br><br>
    <font size="+1">Your email address:</font><br>
    <input name="email" size=50>
    <br><br>
    <font size="+1">Reason for inquiry:</font><br>
    <input name="subject" size=50>
    <br><br>
    <font size="+1">Your comments or questions:</font><br>
    <textarea wrap=physical name="comments" rows=8 cols=50></textarea>
    <br><br>
    <input type="submit" value="Send comments">
    <input type="reset" value="Clear">
    <br><br>
    </form>
    
    <hr>
    </body>
    </html>
    



    The web HTML above is for a simple form. For more detailed instructions on form creation see this tutorial. Now for a closer look at how this form works.

    Note that the method is POST and that the action is /cgi-bin/comments.pl. This means that when the form is completed, the CGI program named "comments.pl" will be executed. The data supplied to this program will be the items entered by whoever fills out the form. This cgi program must be in your cbi-bin directory for the form to be processed correctly. This particular CGI program will mail the contents of the form to a specified email address as well as displaying it as a web page. The value info@MY_COMPANY.com in the sample form should be replaced with a valid email address or alias where the results of the form are to be mailed.

  2. Make/get the CGI Program
    Obtain or make a CGI program. For our example the CGI program that will process the information and mail it to you can be viewed here. This program was written by Juan Lorenzana and is released to the general public. In the next step you will be instructed to download it.

  3. Install Components
    Now install the components described above. Make sure you install all of them, and that you place them in the correct locations.

    1. Download the HTML Source
      You will need to download the HTML Source using FTP and place it on your web server. Feel free to add your own graphics or to change the wording to suit your company's needs. However, be sure not to change the variable names for the input fields or else the form will not work correctly with this sample CGI program.

    2. Download the CGI Programs
      Now download two cgi's for the processing to go smoothly. You may view them beforehand here: comments.pl and cgi-lib.pl. (The first is the program that processes the form and the second is a general library needed by this program.) To download follow the steps below, depending on whether you are a customer or not.


      Customers
      1. Log in to your account.
      2. Change directories to your cgi-bin directory.
      3. Type "tar -xvf /usr/local/contrib/comments.tar" This UNIX command will create the two required files in your cgi-bin directory.


      Other(Then Sign Up)
      1. Download the two source code files and place them in your cgi-bin directory.
      2. Make sure to make then executable by using the chmod command
      3. Type "chmod 755 comments.pl cgi-lib.pl"


    3. Customize the source code
      Feel free to change the form.html and add graphics and links. You can also add other fields and adjust comments.pl to properly process the new fields.

    4. Check it out!
      Now using your web browser call up the page where you have placed the form. Fill out the form with some test data, and (if everything has been done correctly) you will receive an email message with the data from the form. Voila!

 

See also

Counting your visitors



Copyright © 1996 - 2007, ITWest, Inc. All rights reserved
help support order sales home