George Fox University | Offices and Services | Institutional Technology | Creating a Form to E-mail Webpage

Creating a Form to E-mail Webpage

In order to gather information from your webpage viewers, you need to create a form that will capture that information and process it. This tuitorial will focus on creating a form that your web viewer can use to input their data, and configuring the form so that the data will be packaged in an email and delivered to the email address(es) of your choice.

We are going to use a Perl script called FormMail. FormMail is a generic WWW form to e-mail gateway, which will parse the results of any form and send them to the specified user. This script has many formatting and operational options, most of which can be specified through the form, meaning you don't need any programming knowledge or multiple scripts for multiple forms.

For detailed information about how the script works, visit the readme file on the References page.

Once you work your way through the following sections, you'll have working knowledge on what it takes to send email from a web form.

  1. Overview
  2. The Basics
  3. Making It Work
  4. Text Paragraphs
  5. Radio Buttons
  6. Checkboxes
  7. Select Lists
  8. Thanking the User (sending a response webpage)
  9. Putting it all together
  10. Best Practices (Thinking about Usability)
  11. References
  12. A Printable version of this document

Let's start building a form.



<form method="post" action="" name="example1">
</form>

These "form" tags create the shell of every web form you'll create. They don't do anything by themselves, but they are the holders for all the meat of the form. Let's look at three important attributes in the opening form tag.

  1. METHOD - you'll always want a method attribute, because this determines the way that the data is transmitted to the script. Use "post" on these forms.
  2. ACTION - if you want the data to go somewhere or do something, you'll need a value to the action attribute. This is usually a script. We'll give you the value to use here later.
  3. NAME - although a name is not required for the script to work, it's a good idea to include it now, as it will be required if you use JavaScript at a latter date.

Okay, let's make this form do something.

Copy this code and paste it into a plain text word processor, like Windows Notepad.



<form method=post action="https://scripts.georgefox.edu/cgi-bin/FormMail.pl" name="example2">
<input type=hidden name=recipient value=bweldon@georgefox.edu>
<input type=text size=40 name=VacationSpot value="where do you like to vacation?">
<br><input type=submit name=submit value=submit><input type=reset name=reset value=reset>
</form>

Notice we've added a value to the form action attribute. Use:
- https://scripts.georgefox.edu/cgi-bin/FormMail.pl (this is case sensitive).

We've added a special input type whose type value is "hidden". This input type is special because, like the value states, from the web page, it's invisible or hidden. Let's talk about it's attributes.

  1. TYPE - when set to "hidden", the hard-coded name/value pair will be passed to the script, but there will be no indication on the webpage.
  2. NAME - when set to "recipient", the script will gather all the form elements and package them into an email, to be sent to the email address attached to the "value".
  3. VALUE - use the foxmail email address you want the form data sent to. If you want the form data to be sent to a variety of people, list their email addresses within the quotes, each seperated by a comma.

We've added a place for text input. Let's talk about it's attributes.

  1. TYPE - when set to "text", you'll get a one line text box that brief text can be typed into.
  2. SIZE - this denotes the approximate width of the text box on the web page.
  3. NAME - although a name is not required for the script to work, it's a good idea to include it now, as it will be required if you use JavaScript at a latter date.

And what about the submit and reset buttons?

  1. TYPE - when set to "submit", you'll get the submit button. Pretty much required. (Reset is optional - probably useful if your user is going to reuse the form multiple times, ie entering product data)
  2. NAME - although a name is not required for the script to work, it's a good idea to include it now, as it will be required if you use JavaScript at a latter date.
  3. VALUE - this sets the visible text on the button.

The form should look like this on a web page now.



Adding a multi-line text box

Okay, a brief line of text is great for inputting a name or address, but what if you want to capture a paragraph? Enter the textarea tag. Here's your next snippet of code:



<form method=post action="https://scripts.georgefox.edu/cgi-bin/FormMail.pl" name="example3">
<input type=hidden name=recipient value=bweldon@georgefox.edu>
<textarea rows=4 cols=30 name=WhyThere>why there?</textarea>
<br><input type=submit name=submit value=submit><input type=reset name=reset value=reset>
</form>

The TEXTAREA tag provides a place for a paragraph (or more) of text. To use this tag, you'll need to include both opening and closing tags. Let's talk about it's attributes.

  1. ROWS - a number like 4 will give the user a box that will accept 4 lines of text before scrolling begins.
  2. COLS - this denotes the approximate width of the textarea on the web page.
  3. NAME - although a name is not required for the script to work, it's a good idea to include it now, as it will be required if you use JavaScript at a latter date.

The form should look like this on a web page now.



Adding single selections with Radio Buttons

If you have a limited selection, only want the user to select one choice, and you want to control the choices, try using a radio button tag.



<form method=post action="https://scripts.georgefox.edu/cgi-bin/FormMail.pl" name="example3">
<input type=hidden name=recipient value=bweldon@georgefox.edu>
My favorite vacation temperature is ...<br>
<input type=radio name=temperature value="in the 60's">in the 60's<br>
<input type=radio name=temperature value="in the 70's" checked>in the 70's<br>
<input type=radio name=temperature value="in the 80's">in the 80's<br>
<br><input type=submit name=submit value=submit><input type=reset name=reset value=reset>
</form>

The RADIO BUTTON tag allows you to create a list of items that you want the user to select from, but only select one item. You can even pre-select an item for them. You can have as many radio buttons as you want. Let's talk about it's attributes.

  1. TYPE - when set to "radio", you'll get the radio button. Required for each radio button you want.
  2. NAME - required to group the radio buttons together.
  3. VALUE - this is the data value that will be sent to the email receipent.
  4. CHECKED - when included, this will pre-select the radio button. Optional, can only be used on a single radio button.

The form should look like this on a web page now.

My favorite vacation temperature is ...
in the 60's
in the 70's
in the 80's


Using Checkboxes to allow multiple selections

If you have a limited selection, want to give the user the ability to select multiple choices, and you want to control the choices, use a checkbox tag.



<form method=post action="https://scripts.georgefox.edu/cgi-bin/FormMail.pl" name="example3">
<input type=hidden name=recipient value=bweldon@georgefox.edu>
I'd accept a free ticket to ...[check all that apply]<br>
<input type=checkbox name=destination-hawaii value=yes>Hawaii<br>
<input type=checkbox name=destination-london value=yes>London<br>
<input type=checkbox name=destination-portland value=yes>Portland<br>
<br><input type=submit name=submit value=submit><input type=reset name=reset value=reset>
</form>

The CHECKBOX tag allows you to create a list of items that you want the user to select from, and they can even make multiple selections. You can even pre-select items for them. You can have as many checkboxes as you want. Let's talk about it's attributes.

  1. TYPE - when set to "checkbox", you'll get the checkbox. Required for each checkbox you want.
  2. NAME - this is the name part of the name/value pair that will be sent to the email receipent.
  3. VALUE - if the checkbox is checked, this is the data value that will be sent to the email receipent.
  4. CHECKED - when included, this will pre-select the checkbox. Optional, and can be used on multiple checkboxes.
I'd accept a free ticket to ...[check all that apply]
Hawaii
London
Portland


Select lists

By using the "select" tags, you can provide a predetermined list of items from which the user can choose. The select tag uses a nested "option" tag to define each choice. Take a close look at this code to see what I mean.



<form method=post action="https://scripts.georgefox.edu/cgi-bin/FormMail.pl" name="example4">
<input type=hidden name=recipient value=bweldon@georgefox.edu>
I'd like to vacation during the month of:<br>
<select>
  <option name=month value=jan>January
  <option name=month value=feb>February
  <option name=month value=mar>March
  <option name=month value=apr>April
  <option name=month value=may>May
  <option name=month value=jun>June
  <option name=month value=jul>July
  <option name=month value=aug>August
  <option name=month value=sep>September
  <option name=month value=oct>October
  <option name=month value=nov>November
  <option name=month value=dec>December
</select><br>
<br><input type=submit name=submit value=submit><input type=reset name=reset value=reset>
</form>

  1. NAME - this is the name part of the name/value pair that will be sent to the email receipent. Use a common name to group the choices together.
  2. VALUE - this is the data value that will be sent to the email receipent.
I'd like to vacation during the month of:



Thanking the User

By including another "hidden" tag in the form, you can send the user to a specially constructed webpage that can thank them for filling out your form, or give them additional information, ie "Your vacation tickets will be mailed to you within 24 hours..."



<form method=post action="https://scripts.georgefox.edu/cgi-bin/FormMail.pl" name="example5">
<input type=hidden name=recipient value=bweldon@georgefox.edu>
<input type=hidden name="redirect" value="http://brainstorm.georgefox.edu/eform/thanks.html">
Send my free ticket...<br>
<input type=checkbox name=send-24hrs value=yes checked>within 24 hours<br>
<br><input type=submit name=submit value=submit><input type=reset name=reset value=reset>
</form>

  1. TYPE - when set to "hidden", the hard-coded name/value pair will be passed to the script and acted upon, but there will be no indication on the webpage.
  2. NAME - use a value of "redirect" to cause the web server to "serve up" a custom designed webpage of your choice.
  3. VALUE - this is the full path of the returning webpage.
Send my free ticket...
within 24 hours


Putting it all together

By using the form related tags discussed so far, you can now create HTML forms thatcan be used for a wide range of data gathering activities.

Review and/or discuss the benefits of each form tag. When would each one be best used?


Best Practices (Thinking about Usability)

Request as little information as needed.

Make the form self explanitory.

Use them wisely.


References

This tutorial was based upon information gleaned and adapted from a WebMonkey and their Forms Tutorial and the FormMail author's readme file.

Addition information and references:

This page was last updated 4-4-2008 21:51:27.
For questions or comments about this page, please email the webmaster.