Artemis Project Web Site
Section 9.4.1.
Home Tour Join! Contents Team News Catalog Search Comm

WWW Page Form Tutorial

There have been several requests for new web pages on the Artemis Project web site that need to include forms for submitting requests and suggestions which will help us get to the moon. Since forms are becoming more and more commonplace as the Artemis Project web site grows, here is a little overview of creating your own forms so that many of you can create your own forms.

Web page forms are not difficult to do. There is a lot of reference material available on the web to show and demonstrate all of the different aspects of creating and using forms. Many of the initial ECTC forms were set up using instructions available from links on a "How to do forms" page at NC State University, which is unfortunately no longer available on the web. Another useful reference for the syntax of the HTML form tags is the "Mosiac for X version 2.0 Fill-Out Form Support".

The basic part of every form is a block of text and HTML tags in a web page that is surrounded by the <form> and </form> HTML tags. Here is the form section of the "join the ECTC" form:

<form method="POST" action="">
<table border=0 rowspan=4 colspan=2 cellspacing=5>
<tr><td><b>Member Type:</b></td>
<td><select name="Type">
<option> Member
<option> Representative
<option> Observer
<tr><td><b>Your Name:</b></td>
<td><input type="text" size=60 name="Name"></td></tr>
<tr><td><b>E-mail Address:</b></td>
<td><input type="text" size=60 name="Email"></td></tr>
<tr align=top><td><b>Comments:</b></td>
<td><textarea name="Comments" rows=10
<center><input type=submit value=" Join "></center>

As you can see, there isn't that much to it. In fact, much of the above HTML is the table formatting used to line up the form fields, which is unrelated to the form processing itself. The key part of the form tag is the "action" keyword, which identifies the CGI (Common Gateway Interface) script that is run on the web server when the user presses the submit button (labeled "Join" in this form). CGI scripts are discussed a little later on. The different form fields used in this example are the "select" field type, which presents a list of choices, the input field for regular data input and the button, and the text area field for free-form text input. There are two types of input fields used here, the "text" type for normal text input, and the "submit" type used for the Join button. The "select" field type includes a list of possible choices, each one on its own line preceeded by the "option" HTML tag.

Now on to the CGI scripting part of this process. This form, like many other web forms, simply generates an e-mail message with the data from the form that is sent to a specified address. The CGI script that is executed by this form simply reads the data sent from the form, formats it into a mail message, and executes the system command to mail the message. Because it is well suited for text data processing, most web forms use Perl as the script language for CGI processing. Here is the Perl script used for the "Join the ECTC" form:


# Define constants
$recipient = '';

#Print out what we need
print "Content-type: text/html\n\n";
print "<Head><Title>Thank you</Title></Head>";
print "<Body><H1>Thank you</H1>";

#Get the input
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});

#Split the name-value pairs
@pairs = split(/&/, $buffer);

foreach $pair (@pairs)
    ($name, $value) = split(/=/, $pair);
    $value =~ tr/+/ /;
    $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;

    # Stop people from using subshells to execute commands
    $value =~ s/~!/ ~!/g;

    $FORM{$name} = $value;

# Now send mail to $recipient

if ($FORM{'Email'} eq "") {$FORM{'Email'} = 'unknown';}

open (MAIL, "|/usr/lib/sendmail -t");

print MAIL "To: $recipient\n";
print MAIL "From: $FORM{'Email'}\n";
print MAIL "Reply-To: $FORM{'Email'}\n";
print MAIL "Subject: New ECTC Member\n\n";

print MAIL "$FORM{'Name'} at $FORM{'Email'} has joined the ECTC as a
print MAIL  "-------------------------< Comments >-----------------------\n";
print MAIL "$FORM{'Comments'}";
print MAIL "\n-----------------------------------------------------------\n";
print MAIL "\nRemote host: $ENV{'REMOTE_HOST'}\n";
print MAIL "Remote IP address: $ENV{'REMOTE_ADDR'}\n";
close (MAIL);

print "Thank you for joining the ECTC!<P>";

Once again you can see that there isn't that much to this CGI script. Even without knowing Perl, one can easily figure out what most of the script is doing. At the beginning of the script we set up a variable that contains the destination address of the mail message. This will make it easier to change that address as needed in the future. After that the script generates the initial response that is sent back to the user.

One key thing to remember is that all output from a CGI script is sent back to the user as if it was a requested web page. Consequently, anything "printed" by the CGI script (as is done by the "print" statements above) needs to be true HTML as if it was a static web page. That's why the output from a CGI script always has to start with the "Content-type" tag to tell the Web browser what type of document it's receiving. The "foreach" block of the CGI script parses the form data (which is passed as a command-line parameter to the CGI script) into a set of variables that we later use in building the mail message. The script then opens a connection to the "sendmail" program, which is used to mail the message, and generates the text that is the body of the mail message. The last print statement is the last part of the web page that is returned to the user as the result of the CGI script.

Currently, most CGI scripts on the Artemis Project web site are stored in the /bin directory. If you want to have a new CGI script put on the web server, submit it as a new document to the Artemis Web System at If you have any problems using the above guidelines, contact the ASI Web Team at and someone will be happy to help.

Artemis Project Web Site

Home Tour Join! Contents Team News Catalog Search Comm
ASI W9600353r1.2. Copyright © 2007 Artemis Society International, for the contributors. All rights reserved.
This web site contains many trade names and copyrighted articles and images. Refer to the copyright page for terms of use.
Author: Randall Severy. <> Maintained by ASI Web Team <>.
Submit update to this page. Maintained with WebSite Director. Updated Sun, Jan 3, 1999.