Forms Processing


Here is the code for the mailer CGI script. It outputs a fill-out form containing multiple input fields when it is run without passing it any query arguments. Submitting the form runs the script again; the content of the filled-out form are then passed as input to the querysh wrapper program, which parses the input and puts each field's content into a variable that the script can use. The script composes and mails a message to a pre-set address; this message is also returned as the output document.

#!/usr/local/etc/querysh
#?/bin/sh

# mailer - process WWW feedback form, and e-mail filled-in form
#	 - uses querysh to parse input from POST query
#
# (c) 1995, Gilles Detillieux, Physiology, University of Manitoba.

if [ -z "$QSH_Fields" ]
then
	# No form fields given -- send empty form
	cat <<!
Content-type: text/html

<HTML>
<head><title>Gilbert's Mail Box</title></head>
<body><h1> <img src="/icons/text.xbm" alt=""> Gilbert's Mail Box </h1>
<h2>Send a Question, Comment or Suggestion to Gilbert</h2>
<dl>
<dt>Note:
<dd>Please enter all of the information, then use the Submit button
at the bottom of the page.
</dl>
<!-- form method="POST" action="http:/cgi-bin/mailer" -->
<!-- form method="POST" action="http:/~gedetil/setupwww/cgi-bin/mailer.sh" -->
<form method="POST" action="mailer.sh">
<h2>Type :<br>
<input name="mailtype" type="radio" value="Comment" checked>Comment<br>
<input name="mailtype" type="radio" value="Suggestion">Suggestion<br>
<input name="mailtype" type="radio" value="Help">Help!<br>
</h2>
<h2>Name <b>(optional)</b> :<br>
<input size=40 name="username"></h2>
<h2>Email <b>(should you want a reply; also optional)</b> :<br>
<input size=40 name="emailid"></h2>
<h2>Comments :<br>
<textarea name="comments" rows=10 cols=60></textarea>
</h2>
<p>
<input type="reset" value="   Clear Form   ">
<input type="submit" value="   Submit Comments   ">
</form></body>
</HTML>
!
	exit
fi

mydom="cs.umanitoba.ca"
dest="gedetil@${SERVER_NAME:-$mydom}"
from="${QSH_emailid:-www@${SERVER_NAME:-$mydom}}"
name="${QSH_username:-${SCRIPT_NAME:-mailer} script}"
rcvd="Received: from ${REMOTE_HOST:-${REMOTE_ADDR:-unknownhost}} by ${SERVER_NAME:-`hostname`} with HTTP"

/usr/lib/sendmail -oi -oem "$dest" <<!
$rcvd
Errors-To: $dest
To: $dest
From: $from ($name)
Subject: WWW form response - $QSH_mailtype
X-Referer: $HTTP_REFERER
X-User-Agent: $HTTP_USER_AGENT

According to $QSH_username ($QSH_emailid):
$QSH_comments
!

cat <<!
Content-type: text/html

<HTML>
<head><title>Mail Box Entry</title></head>
<body><b>Your message has been mailed:</b></p><hr><pre>
To: $dest
From: $from ($name)
Subject: WWW form response - $QSH_mailtype

According to $QSH_username ($QSH_emailid):
$QSH_comments
</pre><hr>
<b>Thanks for writing. Your comments are always appreciated.</b>
</body>
</HTML>
!

* Seminar Index |* Simple Query Gateway |* Style and Substance
Copyright (c) 1995, Gilbert Detillieux, Computer Science, University of Manitoba.