WWW based forms

And Documentation for a generic C/C++ cgi handler

Written by Paul Bourke


Form items

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.

Hidden field It's here but you can't see it.
Check boxes
Input field
Password field
Radio buttons Set 1:       Set 2:
Scribbling
Text field
Menu select
Text area
Numerical input
Image submit button
Reset form
Submit button
 

Clicking on one of the submit buttons will display the text sent to the cgi except that the "&" between the fields has been replaced with a carriage return.

int main(int argc,char **argv)
{
   int c;

   printf("Content-type: text/html\n\n");
   printf("<pre>");
   while ((c = getchar()) != EOF) {
      if (c == '&')
         putchar('\n');
      else
         putchar(c);
   }
   printf("</pre>\n");
}
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.

Specification

Sample form

Name:
Address:
Email: (Required)
Age:
Cars None
One
Two
More then 2
Travel by car
bus
train
tram
taxi
Comments:
  This forms sends an email message that looks like the following.
From: paul@bourke.gen.nz
Date: Sun Apr 13, 2003  4:32:50  PM Australia/Brisbane
Subject: Contents of WWW form
Reply-To: paul@bourke.gen.nz

A title for the email message
Host: launceston-atm.vic-remote.bigpond.net.au
Browser: Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en) 
         AppleWebKit/60 (like Gecko) Safari/60
---
Name: Paul Bourke
Address: Here and there
Email: paul@bourke.gen.nz
Age group: Private
Cars: None
Car: Yes
Taxi: Yes
Comments: What a silly survey.
---
End of message