WWW based forms
And Documentation for a generic C/C++ cgi handler
Written by Paul Bourke
The following form contains the majority of standard items supported
by forms in HTML. To see how to create a form with these items simply look
at the html source for this page. Note that not all of these may be
supported by the browser you are using, for example, I can't find a
browser that supports "scribbling" or the numeric-range input.
Emailing the contents of a form
Perhaps the most common action to be taken on a form contents
is to email the entered information to an email address. The
following is the documentation (and example) of a C/C++ program
I have written that deals with this. The form is given below to
illustrate the features, as before look at the source to see how
things are done.
- Fields are written to the email message along with their
values. To make this more readable it is recommended that field
names end in a colon. So for example a field as follows
<input type=text name="Name:" value="">
Will appear in the email message as
Name: Paul Bourke
Inserting documentation, titles, footers etc in the email that don't appear
on the form is achieved by using hidden fields with names starting
with "_Text:". For example
<input type=hidden name="_Text:" value="A title for the email message">
- The cgi needs to know the email addresses to send the form data to.
This is accomplished by including up to 2 email addresses as arguments to
the cgi, each email address is separated by "&". For example
<form action="firstname.lastname@example.org" method="post">
this cgi can also check fields that must filled in. Compulsory fields are indicated
by their names which start with a "*". See the error file specification for the
action taken on an missing compulsory field. For example
<input type=text name="*Name:" maxlength=60 size=20 value="">
- It is generally convenient to have a specific subject set in the email. This is
accomplished with a hidden field with the name "_Subject:". For example
<input type=hidden name="_Subject:" value="Contents of WWW form">
- If there are no errors a file (normally formatted as html) is sent back to
the browser. The name of this file is specified in a hidden field called
"_OkFile:", for example
<input type=hidden name="_OkFile:" value="allOK.html">
A generic success message will be sent if this field doesn't exist.
- If there are some errors, eg: compulsory fields not supplied, then a file
is sent back to the browser. The name of this file is specified in a hidden
field called "_ErrorFile:", for example:
<input type=hidden name="_ErrorFile:" value="error.html">
A generic error message will be sent if this field doesn't exist.
- If a field with the name "Email:" is encountered then it is used as
the "From" field of the email message....so replying to the email will work.
<input type=text name="Email:" size=30 value="">
If the email field is compulsory then use the following
<input type=text name="*Email:" size=30 value="">
- If an internal error message is generated then an informative message
is displayed for the user to report to the site administrators.
This is also useful for debugging problems.
- If you're running Apache with server side includes enabled then other
globals can be included with the emails, for example the browser the
person is using and the address of their machine.
<input type=hidden name="Host:" value="<!--#echo var="REMOTE_HOST" -->">
<input type=hidden name="Browser:" value="<!--#echo var="HTTP_USER_AGENT" -->">
This forms sends an email message that looks like the following.
Date: Sun Apr 13, 2003 4:32:50 PM Australia/Brisbane
Subject: Contents of WWW form
A title for the email message
Browser: Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en)
AppleWebKit/60 (like Gecko) Safari/60
Name: Paul Bourke
Address: Here and there
Age group: Private
Comments: What a silly survey.
End of message