CASE.EDU:    HOME | DIRECTORIES | SEARCH

Case Western Reserve University

Information
Technology
Services

 
 

Mailform script for AuroraCGI


The mailform cgi script is used to mail form data to a particular address and simultaneously display a new page in the web browser. This could also be done in JavaScript, but a cgi script does not have browser dependencies, as JavaScript does.

Mailform inputs

Certain inputs appearing in the form control how mailform works. Actually, they most likely will not "appear" in the sense of being visible - you'll probably want to make them hidden - but they must exist in the form to have any effect. (The markup of an example form is shown below.) The inputs are:

mf_mailto
The e-mail address which will receive the form submission data. If an error occurred while sending the mail, a message to that effect is displayed, followed by the failure page.
mf_mailfrom
The e-mail address which will appear as the "From:" line of the message. This can be used to make the mail message appear to come from the person submitting the form by prompting for this information in the body of the form. For instance:
<p>Enter your e-mail address: <input type="text" name="mf_mailfrom"></p>
mf_subject
The subject to use in the mail message.
mf_fields
A list of the form field names, separated by spaces, that should be included (with their values) in the mail message. See the note on conditional field inclusion.
mf_format
A string used to format each line of the mail message. The default is "%f: %v", which, for each value of each field named in mf_fields, results in a line of the form "field: value". The "%" character is used to specify something to be inserted in the line as follows:
%%
a literal percent sign.
%f
the input field name, as it appears in mf_fields.
%u
the field name, with underscores substituted for characters that are not alphanumeric or underscore.
%v
the field value.
mf_reqfields
A whitespace-delimited list of required form fields. If any of these fields are left blank, no mail is sent, and the list of required fields that were left blank is displayed, followed by the failure page. See the note on conditional field inclusion.
mf_title
Specifies the title of the new page. This will appear both between <title>-</title> and <h1>-</h1>.
mf_headtags
A string containing HTML tags to be included between <head> and </head> in the displayed page.
mf_bodyattrib
HTML attributes for the <body> tag of the displayed page.
mf_success
If this begins with a slash ("/") it is interpreted as a filename, relative to your Aurora home directory, to display if all required inputs were provided and mailing was successful. If it does not begin with a slash, then the value of mf_success itself is displayed in the new page. If the field is not present in the form, a default value of "Success!" is used.
mf_failure
Displayed if required fields are missing, or if mailing failed. mf_failure is interpreted the same as mf_success - slash indicates a filename, anything else indicates the message itself.
mf_maintainer
The e-mail address that will be displayed (and linked to) in the footer. If this field is not present, the value of mf_mailto is used.

Notes

Instructions for use

To use this script, create the cgi/ and cgi/bin/ directories in your Aurora home directory. Copy the script from
http://www.case.edu/help/AuroraCGI/mailform into your cgi/bin/ directory. Any changes that need to be made for your particular needs, if any, can then be made to your copy. An example form using mailform (for an account named "Acct" maintained by abc123@case.edu):
<form method="post" action="/cgi-bin/AuroraCGI/Acct/mailform">
<input type="hidden" name="mf_title" value="Example Form Results">
<input type="hidden" name="mf_headtags" value='<base href="http://www.case.edu/Acct/">'>
<input type="hidden" name="mf_bodyattrib" value='bgcolor="silver"'>
<input type="hidden" name="mf_mailto" value="abc123@case.edu">
<input type="hidden" name="mf_subject" value="Example output">
<input type="hidden" name="mf_success" value="It worked!">
<input type="hidden" name="mf_failure" value="/stuff/failure.html">
<input type="hidden" name="mf_fields" value="foo bar">
<input type="hidden" name="mf_reqfields" value="foo">
Foo:<br>
<input type="text" name="foo"><br>
Bar:<br>
<input type="checkbox" name="bar" value="bar1">Bar1
<input type="checkbox" name="bar" value="bar2">Bar2
<input type="checkbox" name="bar" value="bar3">Bar3
<br><input type="submit">
</form>

Note: to test this form, you must replace "Acct" with your Aurora APAS user id, and "abc123@case.edu" with your e-mail address. For help with writing HTML forms, see the forms chapters of the Intermediate HTML tutorial.

If the user entered "hello" in the foo field and checked the first and third checkboxes of bar, the mail message would appear as:

foo: hello
bar: bar1
bar: bar3

If the user forgot to fill in the foo field, the page displayed would appear as:

[Aurora header]
The following required field(s) were not entered: foo.
[Contents of the file failure.html, in your stuff/ directory]
[Aurora footer]