WillMaster Possibillites Logo EzineSeek Award
Nitty Gritty Lowdown
by
Mari Bontrager

Permission is granted to reprint this article in its entirety, provided no reprints are sent in conjunction with unsolicited bulk email, provided no fee or other value is exchanged, provided no changes are made to the article, and provided the author's name, signature lines, and copyright line are printed with the article; except you may change the article's title.

Today's article addresses the Nitty Gritty Lowdown on creating forms that work with CGI scripts.

It will help to keep these things in mind:

  1. Most forms have terminology and syntax in common.
  2. Each form must be constructed to communicate with a specific CGI script.
  3. We are going to learn about #1 and #2.

We will assume you are familiar with what a form looks like — usually little boxes for you to type information into, such as name, email address, and the like. Or it may have buttons or check boxes to click. Yes, you have the picture.

For today's purpose we will say that a form is special HTML code that allows someone, through a web browser, to communicate with a CGI script.

Now this is Nitty Gritty Lowdown #1:

A form without a script to talk to is like a heifer on ice skates. It's getting no where very fast.

This is why your script is going to have an "action=" tag in it. "Action=" tells your form where to find the script it wants to talk to.

Remember I said forms have terminology and syntax (think sentence structure) in common.

These tags (terms) are often found in forms.

method (how a script expects to receive the information)
action
input type
hidden
text
radio
checkbox
submit
textarea
name
value

These words are simply HTML tags that tell the browser how to display the form and what to do with the information you type in. You will often see a tag similar to this:

<input type="text" name="email" size="21">

Let's break down that example:

This part:

<input type="text"

is used by the browser just like any other HTML tag to determine how to show the form on the page. A "text" field is a box of the designated length (size="21") that can be typed into.

Now here's Nitty Gritty Lowdown #2:

We send information to a CGI Script by attaching a "value" to a "name". In that example above, the "name" is "email". The "value" is whatever is typed into the box in the browser window.

This brings us to Nitty Gritty Lowdown #3:

CGI scripts are individuals. They each know different things and will understand" only specific "name"s. A very simple script may only understand two "name"s. A complex script may understand hundreds.

So how do you know what your script is going to understand? I am sorry to break this to you but you need to read the documentation that comes with the script. (If there isn't any documentation, find a better script.)

You could create a beautiful form with hundreds of questions that collects all sorts of data, but it will do you no good if your script only understand three words. Each script understands a specific vocabulary.

This is a good time to look at a demonstration form: http://willmaster.com/a/12/pl.pl?art121

The script to which the form will "talk" is Master Feedback, a very simple (and free) CGI script from the Master Series.


Creating forms for Master Feedback:

Master Feedback's function is to receive information from a form and send it to you in an email. That is all it does.

Master Feedback has a limited vocabulary and (like most CGI scripts) is picky about details.

Punctuation counts! Watch all quotation marks, commas, single quotes, semicolons, everything. If your form doesn't work, look at those things first.

Master Feedback knows 5 specific names:

subject redirect
realname
email
message

But it has a handy-dandy catchall name that it will use to spit back in an email any other information you want it to gather. (Smarter than the average bear er.. um... simple script.)

Any way, other information you want to be gathered by your form and sent to you in an email must be formated this way:

name="x_SPECIAL NAME" Change SPECIAL NAME to a word or words of your choosing, so long as it isn't one of the original 5 it already knows. You may include numbers, spaces, letters.

Each SPECIAL NAME must be unique!

It is helpful to remember that these x_ fields appear in alphbetical order on your email — after the names that Master Feedback already knows and is sending to you. (realname, email, message).

Let's look at the example form:

Begin a form with this:

<form method="POST" 
action="http://willmaster.com/cgi-bin/MasterFeedback.cgi">

This says that this is a form using the method POST (Master Feedback expects this) and that this installation of Master Feedback is at http://willmaster.com/cgi-bin/MasterFeedback.cgi

On this line:

<input type="hidden" name="subject" value="Form Demo">

the value is whatever you want the subject of the email sent to you to read.

On this line:

<input type="hidden" name="redirect" 
value="http://willmaster.com/possibilities/demo/thform.html">

the value is the URL of the page the visitor is sent to after the form button is clicked.

NOTE: If you want the email to go to a different email address than the email addy you designated when you installed Master Feedback on your server, put this line next

<input type="hidden" name="MyEmail" value="you#domain.com">

but change the value to the correct email address. Use a # (pound sign) instead of @ symbol. Master Feedback is expecting you to do this and will correct it before sending the email.

Next we see the various input fields:

RADIO BUTTONS:

<input type="radio" name="x_Visitor wants" 
value="order">An order for services.<br>
<input type="radio" name="x_Visitor wants" 
value="information" checked>A request for information.

Radio buttons come in sets of two or more (as a rule). Each radio button in a set must have the SAME NAME but different values.

CHECK BOXES:

<input type="checkbox" name="x_1 letter chosen" 
value="a"> A<br>
<input type="checkbox" name="x_2 letter chosen" 
value="b"> B <br>
<input type="checkbox" name="x_3 letter chosen" 
value="c" checked> C 

Check boxes often come in sets but each box must have a DIFFERENT NAME as well as a different value.

TEXT AREAS:

<textarea name="message" cols="40" rows="10"></textarea>

If the name of the textarea is different than message, you would use an x_NAME name. The value is what ever is typed into the box by the visitor. You designate cols and rows to your desired size of course. The text area can be "seeded" with text if you wish. Just type it before the </textarea> tag.

SUBMIT BUTTON: The submit button is typically last:

<input type="submit" value="Send">

Often a name is not required but this depends on what the script is expecting. Master Feedback expects only one submit button and doesn't require a name.

The value Send may be changed to any word you like.

Last, remember the </form> tag at the very end. Very likely, nothing will work without it!

Now to review the Nitty Gritty:

Nitty Gritty Lowdown #1:

A form without a script to talk to is like a heifer on ice skates.

Nitty Gritty Lowdown #2:

We send information to a CGI Script by attaching a "value" to a "name".

Nitty Gritty Lowdown #3:

CGI scripts are individuals. They each know different things and will understand" only specific "name"s.

Now you have the Lowdown. You can use this to make forms for any CGI script. Just find out what "NAME"s it is looking for and construct your form to send it.

Most of all, have fun and watch out for those heifers on ice skates!

By: Mari Bontrager

Copyright 2001 Bontrager Connection, LLC
http://willmaster.com/possibilities/
subscribe-possibilities@willmaster.com