CGI: Form Mail with Required Fields Script

  1. Start the form with:
    <form method="post" action="https://www.yourdomain.com/cgi-bin/reqform" />.
  2. Add the e-mail address you want the form information emailed back to:
    <input type="hidden" name="mailto" value="username@yourdomain.com" />
  3. Add a subject line for the e-mail:
    <input type="hidden" name="subject" value="the subject of the e-mail" />
  4. Create the form fields. See examples below.
  5. Add Submit and Reset buttons:
    <input type="submit" value="Submit" />
    <input type="reset" value="Reset Form" />
  6. Optional: Indicate required fields:
    <input type="hidden" name="required_fields" value="field names separated by commas" />
  7. Optional: Add a custom acknowledgement page:
    <input type="hidden" name="acknowledge_page" value="https://www.yourdomain.com/acknowledge.html" />
  8. Optional: Add formating to the confirmation screen that the user sees before the form is submitted:
    <input type="hidden" name="form_title" value="Title of Form">
    <input type="hidden" name="form_fontsize" value="2" />
    <input type="hidden" name="form_fontface" value="Arial, Helvetica" />
    <input type="hidden" name="form_message" value="Please review the
    information you entered for accuracy.<br /> If you need to make a
    correction, click the BACK button. <br /> If the information shown is
    correct, click the OK button." />
    <input type="hidden" name="table_width" value="50%" />
  9. Optional: Add an e-mail back to the person filling out the form (all four of these lines must be done for this function to work):
    <input type="hidden" name="email_fieldname" value="name of the field that contains the e-mail address" />
    You must have a field in your form where the customer fills in their e-mail address for this to work. You may want to make this a required field.
    <input type="hidden" name="message_from" value="ABC Company" />
    <input type="hidden" name="message_subj" value="Thank you message" />
    <input type="hidden" name="message_file" value="/thankyou.txt" />
    The value for message_file should be the full path to the file relative to the Web root.
  10. End the form: </form>

Commonly Used Form Input Fields

Checkboxes

<label>
   <input type="checkbox" value="zucchini" name="plant" checked /> I like zucchini.
</label><br />
<label>
   <input type="checkbox" value="zebra" name="animal" /> I like zebras.
</label>

  • value is what is returned if the box is checked.
  • name is how this checkbox will be referenced.
  • checked is included if the box should start off checked.

Radio Buttons

<label>
   <input type="radio" value="Jazz" name="Radio1" /> Jazz
</label><br />
<label>
   <input type="radio" value="New Age" name="Radio1" /> New Age
</label><br />
<label>
   <input type="radio" value="Rock" name="Radio1" checked /> Rock
</label>

  • value is what is returned if the box is selected.
  • checked (optional) is the item that starts off selected.
  • name is how this series of radio buttons will be referenced.

Text Fields

<input type="text" value="Kilroy was here." name="text1" size="50" maxlength="70" />

  • value (optional) is a default string to be displayed in the text field before the user types anything.
  • name is how this text field will be referenced.
  • size (optional) is the amount of display space for the text field.
  • maxlength (optional) is the length of one line in the text field. If maxlength is larger than size then the text field should scroll as necessary.

Text Areas

<textarea name="text2"  rows=10 cols=50>Type something here.</textarea>

  • name is how this text area will be referenced.
  • rows and cols define the size of the text area.

Password Fields

<input type="password" name="thepassword" />

  • name is how this field is referenced.
  • When the user types in this field, no characters are displayed.