Wellesley College CWIS Generic Forms Engine
Warning: This is a technical document!
(Contents may be extremely boring to uninterested parties.)
Please note: This document contains all the information you need to make an existing form work on the Wellesley college web server. To learn how to create an HTML form, see the Dreamweaver documentation.
Types of Forms
There are two types of forms to choose from:
- E-mail form
This type of form takes input from a user, and emails the results to address(es) you specify.
- Comma-seperated value form
This type of form takes input from a user, and appends it to a text file which you can later import into a spreadsheet or database.
1. E-mail form
Here is the implementation design for the e-mail form:
- User requests an HTML document containing your form from our CWIS.
- They enter whatever data is necessary to complete the form.
- They press the Submit button you've provided on your form.
- Their browser sends the data back to our CWIS.
- Our CWIS runs the program name you specified in your form, passing the user
data to the program as input.
- The program name you specified will be the Perl script I wrote. This is
where the meat of the process resides:
- Crunches the input data into an usable format.
- Reads the specified template file you created (see Creating
the text template file, below), and plugs in data where required.
- If there are no errors, it will e-mail the filled-in template to whomever
you told it to mail it to in your form (see Creating a form, below).
- A quick HTML document is sent to the user's browser saying the operation
was a success.
- If there are errors, a different HTML document is sent to the user's
browser describing the error.
By design, this Perl script will serve most everyone's purpose for e-mailing
the contents of any fill-out form.
You need to create two files on the CWIS machine using a login account. If
you do not have one, please contact our Webmaster.
Creating a form
- Write your HTML document with the fill-out form in it.
- Do NOT name any of your fields "email." You are going to have
a hidden field named email, and having the duplicate fields will interfere
with the form functionality, sometimes without giving you an error message.
- Add the following two fields inside the form:
<INPUT TYPE="HIDDEN" NAME="FILE" VALUE="filename">
<INPUT TYPE="HIDDEN" NAME="EMAIL" VALUE="address address ...">
Where filename should be the full pathname of a text file template
which resides on the CWIS machine itself (for example, "/www/data/Department/foo/bar.txt")
- *not* a URL! Each address is an e-mail address of a recipient.
Use spaces to separate addresses if multiple recipients are specified. You may
have forms sent to FirstClass conferences, but you must make special arrangements
with the Digital
Technologies group.
You may also specify a subject for this piece of mail.
To specify a subject:
- include a field name called _SUBJECT either as a hidden field, or something
the user can specify (depending on your application).
- Be sure to see the special note below in the section entitled Creating
the text template file regarding subject lines.
Here are some examples:
<!/****A subject that never changes****/>
<INPUT TYPE="HIDDEN" NAME="_SUBJECT" VALUE="Generic Forms Engine">
<!/****A required subject line the user must enter****/>
<INPUT SIZE=32 MAXLENGTH=32 NAME="_SUBJECT">
To make a field required:
- use a field name which begins with an underscore.
For example:
<INPUT SIZE=32 MAXLENGTH=32 NAME="_NAME">
- The user will be informed if a required field is missing, but won't be told
which one. It is good practice to denote required fields on your form.
To use a different screen other than the default
Done! screen:
- specify a DONESCREEN variable with the complete URL (do not use
a relative path!) you want to return to as the value.
For example:
<INPUT TYPE="HIDDEN" NAME="DONESCREEN" VALUE="http://www.wellesley.edu/~tcantin/mydone.html">
Creating the text template file
This file should contain a template of how you want the e-mail to look.
- Create a text file that looks exactly like the email that you expect to
receive from the form.
- Where there is data to be filled in, put a %%XX, where XX corresponds to
a field NAME from the form you created.
For instance, if my HTML form defined this:
<INPUT SIZE=32 MAXLENGTH=32 NAME="NAME">
Then a line in my template file would be something like:
Your name: %%NAME
- Please note that the values you specify for any NAME="" fields and
any %% variables are converted to uppercase! Therefore, NAME="NAME"
and NAME="name" are identical, and %%NAME and %%name
are identical.
To make a subject line work properly (as mentioned above in Creating
a Form):
- it must be the very first line of your text template file,
- it must be followed by a blank line, and
- it must be formatted as follows:
Subject: %%_SUBJECT
Click here for a simple yet complete example.
I consider this mandatory reading.
Links to examples of actual forms on our CWIS.
2. Comma-seperated value form
Here is the implementation design for the comma-seperated value form:
- User requests an HTML document containing your form from our CWIS.
- They enter whatever data is necessary to complete the form.
- They press the Submit button you've provided on your form.
- Their browser sends the data back to our CWIS.
- Our CWIS runs the program name you specified in your form, passing the user data to the program as input.
- The program name you specified will be the Perl script I wrote. This is where the meat of the process resides:
- Crunches the input data into an usable format.
- Reads the specified template file you created (see Creating the text template file, below), and plugs in data where required.
- If there are no errors, it will write a line of text as per the template to the specified output file (see Creating a form, below).
- A quick HTML document is sent to the user's browser saying the operation was a success.
- If there are errors, a different HTML document is sent to the user's browser describing the error.
By design, this Perl script will serve most everyone's purpose for appending the contents of any fill-out form to a comma-seperated text file.
You need to create three files on the CWIS machine using a login account. If you do not have one, please contact our Webmaster.
1. Creating the HTML form
- Write your HTML document with the fill-out form in it.
- Do NOT name any of your fields "email." You are going to have
a hidden field named email, and having the duplicate fields will interfere
with the form functionality, sometimes without giving you an error message.
- Add the following two fields inside the form:
<INPUT TYPE="HIDDEN" NAME="CSVFILEIN" VALUE="inputfilename">
<INPUT TYPE="HIDDEN" NAME="CSVFILEOUT" VALUE="outputfilename">
Where inputfilename should be the filename of the text file template which resides on the CWIS machine itself (for example, "in.txt") - *not* a URL! This file must exist in the same directory as your HTML file!
You may also have a timestamp automatically prepended by including the following line in your form:
<INPUT TYPE="HIDDEN" NAME="AUTOTIMESTAMP" VALUE="YES">
To make a field in your form required:
- use a field name which begins with an underscore.
For example:
<INPUT SIZE=32 MAXLENGTH=32 NAME="_NAME">
- The user will be informed if a required field is missing, but won't be told
which one. It is good practice to denote required fields on your form.
To use a different screen other than the default
Done! screen:
- specify a DONESCREEN variable with the complete URL (do not use
a relative path!) you want to return to as the value.
For example:
<INPUT TYPE="HIDDEN" NAME="DONESCREEN" VALUE="http://www.wellesley.edu/~tcantin/mydone.html">
2. Creating the text template file
This file should contain a template of how you want the comma-seperated value file to look. Note that each form submission will cause one line of data to be appended to your output file, so your template input file should only be one line!
- Create a text file that containing appropriately placed fields so it looks exactly like the line of data that you expect to be appended.
- Where there is data to be filled in, put a %%XX, where XX corresponds to a field NAME from the form you created.
For instance, if my HTML form defined this:
<INPUT SIZE=32 MAXLENGTH=32 NAME="_NAME">
<INPUT SIZE=32 MAXLENGTH=32 NAME="ADDRESS">
Then my template file would be something like:
%%_NAME,%%ADDRESS
- Please note that the values you specify for any NAME="" fields and
any %% variables are converted to uppercase! Therefore, NAME="NAME"
and NAME="name" are identical, and %%NAME and %%name
are identical.
3. Creating a blank output file
- open a login (telnet) session to www.wellesley.edu
- login with your provider account
- cd to the directory containing the HTML form and the template file
- type "touch filename" where filename is the name of the output file
- type "chmod 777 filename"
Click here for a simple yet complete example. I consider this mandatory reading.
Click here to see it's output (note that you may need to hit the Reload button).