Handout 27
Sending Information Using HTML Forms
The Problem
When we need to get information from an HTML form sent to someone we can use the action="mailto:..."
option of the form tag. This will generate an e-mail message and forward the information to the specified user.
The HTML file shown below uses this option at line 16.
- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
- <HTML>
- <HEAD>
- <META NAME="GENERATOR" Content="Visual Page 1.0 for Windows">
- <META HTTP-EQUIV="Content-Type"
- CONTENT="text/html;CHARSET=iso-8859-1">
- <TITLE>sample c cgi-bin</TITLE>
- </HEAD>
- <BODY TEXT="#FFFF00" BGCOLOR="#AA0000">
- <H3 ALIGN="CENTER">This is a sample cgi-bin program using a perl
- program.</H3>
- <P>
- <HR ALIGN="CENTER">
- </P>
- Enter input for the C sample and click <BR>
- <form method="POST" action="mailto:cpheatt@emporia.edu">
- <br>
- <INPUT NAME="textentry" VALUE="Text Entry Field " SIZE = 20>
- <br>
- <INPUT TYPE="checkbox" NAME="checkbox" VALUE="Check box" CHECKED>
- <br>
- <INPUT TYPE="radio" NAME="radio" VALUE="Radio Button 1" CHECKED>
- <INPUT TYPE="radio" NAME="radio" VALUE="Radio Button 2">
- <INPUT TYPE="radio" NAME="radio" VALUE="Radio Button 3">
- <br>
- <INPUT TYPE="password" NAME="entry1" VALUE="Password" SIZE = 20>
- <br>
- <SELECT NAME="optionmenus">
- <option>Option Menus
- <option>Another Option
- </SELECT>
- <br>
- <SELECT NAME="scrolldown" SIZE = 3>
- <option>Scroll Down Menus
- </SELECT>
- <br>
- <TEXTAREA NAME="multiline" ROWS=3 COLS=30>Multi-Line Text Entry Field</TEXTAREA>
- <br>
- <INPUT TYPE="hidden" NAME="mail_to_address" VALUE="pheattch@emporia.edu">
- <br>
- <input type="SUBMIT" value="ENTER">
-
- </form>
- <P>
- <HR ALIGN="CENTER">
-
- <FORM METHOD="GET" ACTION="mailto:cpheatt@emporia.edu">
- <INPUT TYPE="text" NAME="q" SIZE=45>
- <INPUT TYPE="submit" VALUE="send it"><BR>
- <INPUT TYPE="hidden" NAME="mail_to_address" VALUE="pheattch@emporia.edu">
- <INPUT type=radio name=fs value =web checked>The Web<BR>
- <INPUT type=radio name=fs value = use>Usenet<BR>
- <INPUT type=radio name=fs value = ftp>Ftp<BR>
- <INPUT type=radio name=fs value = nws>Newswires<BR>
- <INPUT type=radio name=fs value = wth>BizNews<BR>
- <INPUT type=radio name=fs value = qte>stuff<BR>
- </FORM>
- <HR>
- </BODY>
- </HTML>
The webpage displayed by the HTML file given above is shown below:

When the user presses the enter button, the information is e-mailed. The information received in the e-mail
message look like the following:
textentry=Text+Entry+Field+&checkbox=Check+box&radio=Radio+Button+1&entry1=Passw
ord&optionmenus=Option+Menus&multiline=Multi-Line+Text+Entry+Field&mail_to_addre
ss=pheattch%40emporia.edu
Not easy to follow what was actually transmitted.
A Solution
A cgi-bin program has been developed that transfers information via e-mail in a more understandable format.
To use this program two things need to be changed in the HTML file:
- The mailto command is replaced by a call to the cgi-bin program. In the above program (line 17):
<form method="POST" action="mailto:cpheatt@emporia.edu">
is changed to
<form method="POST" action="http://anvil.emporia.edu/cs355/mailto/mailto.cgi">
- A hidden form field is added which specifies the e-mail address of the person to receive the mail. The form
of the item is: <INPUT TYPE="hidden" NAME="to" VALUE="cpheatt@anvol.emporia.edu">
The cgi-bin script works witt the POST method of forwarding information.
The HTML file shown below implements the POST method:
- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
- <HTML>
- <HEAD>
- <META NAME="GENERATOR" Content="Visual Page 1.0 for Windows">
- <META HTTP-EQUIV="Content-Type"
- CONTENT="text/html;CHARSET=iso-8859-1">
- <TITLE>sample c cgi-bin</TITLE>
- </HEAD>
- <BODY TEXT="#FFFF00" BGCOLOR="#AA0000">
-
- <H3 ALIGN="CENTER">This is a sample cgi-bin program using a perl
- program.</H3>
- <P>
- <HR ALIGN="CENTER">
- </P>
- Enter input for the C sample and click <BR>
- <form method="POST" action="http://anvil.emporia.edu/~pheattch/cs355/mailto/mailto.cgi">
- <br>
- <INPUT NAME="textentry" VALUE="Text Entry Field " SIZE = 20>
- <br>
- <INPUT TYPE="checkbox" NAME="checkbox" VALUE="Check box" CHECKED>
- <br>
- <INPUT TYPE="radio" NAME="radio" VALUE="Radio Button 1" CHECKED>
- <INPUT TYPE="radio" NAME="radio" VALUE="Radio Button 2">
- <INPUT TYPE="radio" NAME="radio" VALUE="Radio Button 3">
- <br>
- <INPUT TYPE="password" NAME="entry1" VALUE="Password" SIZE = 20>
- <br>
- <SELECT NAME="optionmenus">
- <option>Option Menus
- <option>Another Option
- </SELECT>
- <br>
- <SELECT NAME="scrolldown" SIZE = 3>
- <option>Scroll Down Menus
- </SELECT>
- <br>
- <TEXTAREA NAME="multiline" ROWS=3 COLS=30>Multi-Line Text Entry Field</TEXTAREA>
- <br>
- <INPUT TYPE="hidden" NAME="to" VALUE="cpheatt@emporia.edu">
- <br>
- <input type="SUBMIT" value="ENTER">
- <p>Values of environment variables will be displayed to the screen
- </form>
- <P>
- <HR ALIGN="CENTER">
- </BODY>
- </HTML>
The cgi-bin program forwards an e-mail message of the following form:
From nobody Sat Dec 22 14:59:27 2001
Date: Sat, 22 Dec 2001 14:59:27 -0600 (CST)
Message-Id: <200112222059.fBMKxRv21999@anvil.emporia.edu>
From: sender.did.not.provide.an.email.address@webmail.gateway (WebMail gateway, no From given)
Subject: WebMail:
To: cpheatt@anvil.emporia.edu
Content-Length: 789
textentry = Text Entry Field
checkbox = Check box
radio = Radio Button 1
entry1 = Password
optionmenus = Option Menus
multiline = Multi-Line Text Entry Field
# ------------------------------------------------------------------
# This message comes to you via Wyenets Mailto.cgi
# The person who originated this message may not be provably
# identifiable. Our best guess at the identity of the originator is,
# unknown@64.123.119.82 (http_referer=http://anvil.emporia.edu/~pheattch/cs355/mailto/mailto1.html)
# You can get more information about Mailto.cgi at
# http://wyenet.co.uk/webtools/mailto.html
# Wyenet accepts no liability for messages sent by this Mail Gateway.
# ------------------------------------------------------------------
And the cgi-bin program displays the following screen to the user forwarding the information.

Source
The Perl cgi-bin script (modified to work on anvil) is available here.
The example page above using the script is available here. Link to working
copy on anvil is here.
The example script from Wyenet is available here. Link to working copy on
anvil is here.
A FAQ on the script is available here.
* from here.