[Index of Lessons]
[Advanced Lesson 7]
[Advanced Lesson 9]

A8. Forms

Forms
Forms are one of the hardest pieces of HTML code that will be presented within this collection of HTML pages. Basically a form is a way in which you can add interactivity to a standard web site. It is constructed using <form> and </form> tags, with quite a bit more information inbetween these two tags. With the form tag you can add to your web pages a guestbook, order forms, surveys a different way to get feedback or whatever takes your fancy.
The basic construction of a html form is this...

<form> begin a form
<input> ask for information in one of several different ways...
<input> ...there can be as many input areas as you wish
</form> end a form

To start the form needs to know how to send the information to the server or to you. The two methods that are available are GET and POST.

METHOD="GET"
Most HTML documents are retrieved by requesting a single URL from a server. In accordance, all information from a form using the GET method is appended onto the end of the URL being requested.

METHOD="POST"
This method transmits all form input information immediately after the requested URL or to an email account. In other words, once the server has received a request from a form using POST it knows to continue "listening" for the rest of the information. This is the more common method.

Secondly, the forms need to know where to send the information. This is the URL being requested from the form, and is referenced with the ACTION tag. This URL will almost always point to a CGI script to decode the form results. Remember that if you are referencing a script that lives on the same server as the form, you don't need to include the full URL. Or the ACTION tag points to your email address

What the above information tells you is that a tag forms can have 3 methods of an opening tag, these are :

1.

<form method="post" action="/cgi-bin/post-query">
</form>
That code tells the form that it is accessing a CGI script called post-query, what that script does is upto the designer of that particular script

2.

<form method="post" action="mailto:xxxxxx@xxxxx.xxx.xx">
</form>
This code uses the post method to tell the form that once the form has been used email all of that data to someone's email account.

3.

<form method="get" action="http://www.this.url/some.page.html">
</form>
This code has the useful attribute of placing all of the data collected by a form onto the end of a web page. This is how many guestbooks are written.

Now that you have seen how to open the forms, next comes what do you put on them? Well as stated earlier there are many different Input tags which are used for just this purpose. There are 8 different tags used for the <input type="xxxxx">. This is where the user enters data, let's take a look at each one separatly.

To test a text box yourself, I suggest you type in the box provided, this way you get used to clicking into these forms and the possibilities they represent.

Forms Input
HTML Result
Text
<form method="post" 
action="mailto:xxxxx@xxxx.xxxx">
<input type=text>
</form>

This is the standard text box that gets displayed whenever
you request a form. All following form commands will have the "Post"
method attached to them and the action is to email someone.

Password
<form method="post" 
action="mailto:xxxxx@xxxx.xxxx">
<input type=password>
</form>

The password puts *'s instead of characters when anything
is typed into the text area.

Checkbox
<form method="post" 
action="mailto:xxxxx@xxxx.xxxx">
<input type=checkbox>
</form>

The checkbox can either be empty or filled in, it's a true
/false option.

Radio Button
<form method="post" 
action="mailto:xxxxx@xxxx.xxxx">
<input type=radio>
</form>

The radio button can either be empty or filled in, it's
a true/false option.

Images
<form method="post" 
action="mailto:xxxxx@xxxx.xxxx">
<input type="image" src="email.gif"
width=100 height=62>
</form>

As you can see you can load images within your forms
this could be used instead of the boring "submit" button, shown
later down the page.

Hidden
<form method="post" 
action="mailto:xxxxx@xxxx.xxxx">
<input type=hidden value="
Form on anything">
</form>

A hidden tag is used in a form when there is some information that you
wish to include in a form that you don't want the user to see.
It is normally used in conjunction with the password type. It returns
useful information about specific forms. As you can see, if you have
multiple forms that are the same that get sent to you, you can add a
hidden tag to it, so when it is sent to your email account, there will
a value telling you what the form is about. This is why the hidden tag
should include a value tag.

Submit
<form method="post" 
action="mailto:xxxxx@xxxx.xxxx">
<input type=submit>
</form>

Submit is a button created so that you can click on it
and it sends the form data, via the action requested. The name
of the button can be changed by using the value tag.

Reset
<form method="post" 
action="mailto:xxxxx@xxxx.xxxx">
<input type=reset>
</form>

Reset is a button used for clearing a form of all data.
The name of the button can be changed by using the value tag.
As you can see there are quite a few input type tags, each serves a purpose, by now you should be wondering what if I want 3 or 4 check boxes together? How can I get them to work together? Well this is where another form tag comes into play, the input name tag. As well as the previous 8 input commands there are 5 more, which are normally included after the input type tag has been used. Lets examine each of these with a corresponding input type.

Forms Input Cont...
HTML Result

Name
<form method="post" 
action="mailto:xxxxx@xxxx.xxxx">
<input type=text name="fred">
</form>

The name tag is standard with every type used within a form,
this allows the browser to distinguish between different type
tags and also allows for multiple actions(ie, checkboxes) to work
together to produce one output.

Value
<form method="post" 
action="mailto:xxxxx@xxxx.xxxx">
<input type=text name="fred"
value="turtle">
</form>

The value tag can be used with almost every type found within a form,
this allows the user to basically give big hints on what goes where
on a form, by saying "email here" in a text box in which you want a
user's email address, most times makes it easier upon a user.

Checked
<form method="post" 
action="mailto:xxxxx@xxxx.xxxx">
<input type=radio name="fred"
checked>
</form>

The checked tag can be used with radio tags or the checkbox tag.
This basically makes one in a group of radio tags or checkboxes already
clicked on, you might use this in simple query's such as male or female,
do you want to include your email address yes or no??.

Size
<form method="post" 
action="mailto:xxxxx@xxxx.xxxx">
<input type=text name="fred"
size=30>
</form>

The size tag determines the size of a area, this is normally used
on such tags as the input type=text, this normally limits the size of the
text box for a certain width. The default is set to 20 characters. This is
a decent width, and this doesn't limit the amount of informaton that can
be typed into the text field.

Maxlength
<form method="post" 
action="mailto:xxxxx@xxxx.xxxx">
<input type=text name="fred"
maxlength=15>
</form>

As you saw above, the size command modifies the size of
the text box that is viewed with no limit on the actual amount of data
that can be entered into it. The new tag maxlength creates a limit
on the amount of information entered into a text box. Test it, click into
the text box and attempt to fill it with characters.

Forms Multiple Options
HTML Result

Pull Down Menu's
<form method="post" 
action="mailto:xxxxx@xxxx.xxxx">
<select>
</select>
</form>
To make a Pull down menu, we use the tags <select> and
</select> instead of the <input> tag. As you can see, the basic
tags themselves give you a pull down menu, but it has no length, no data
,nothing. So let's name it (As all form tags should be named) and give
it a few options.

Name's and Options
<form method="post" 
action="mailto:xxxxx@xxxx.xxxx">
<select name="hero">
<option>Batman
<option>Superman
<option>Robin
<option>Flash
</select>
</form>
As is standard the Pull Down Menu is named, Notice how
each option is a separate entity. You can have as many options as you
require

Values and Selected
<form method="post" 
action="mailto:xxxxx@xxxx.xxxx">
<select name="hero">
<option value="Batman">Batman
<option value="Superman">Superman
<option value="Robin">Robin
<option value="Flash selected>Flash
</select>
</form>
By claiming a Value for each option, the option then has
meaning when it is selected. The selected tag, means that the list
doesn't always have to start at the top of the menu.

Scrolling List
<form method="post" 
action="mailto:xxxxx@xxxx.xxxx">
<select name="hero" size=5>
<option value="Batman">Batman
<option value="Superman">Superman
<option value="Robin">Robin
<option value="Flash">Flash
<option value="Storm">Storm
<option value="Cyclops">Cyclops
<option value="Archangel">Archangel
<option value="Prof X" selected>Prof X
<option value="Jubilee">Jubilee
</select>
</form>
As you can see, the only difference between a Pull Down Menu
and a Scrolling list is the Size tag. By specifiy a size the actual height
of the Pull Down Menu is modified. You can also have an option selected
should you so desire.

Radio buttons
<form method="post" 
action="mailto:xxxxx@xxxx.xxxx">
<input type=radio name="hero"
value="Batman">Batman<br>
<input type=radio name="hero"
value="Superman">Superman<br>
<input type=radio name="hero"
value="Robin" checked>Robin<br>
<input type=radio name="hero"
value="Flash">Flash<br>
</form>
Batman
Superman
Robin
Flash
As you have by now no doubt noticed, a selection of radio
tags such as those shown, enable you to select one option of the choice
avaliable. Also note that a choice can be either checked or not checked.

Check boxes
<form method="post" 
action="mailto:xxxxx@xxxx.xxxx">
<input type=checkbox value="yes"
name="Batman">Batman<br>
<input type=checkbox value="yes"
name="Superman">Superman<br>
<input type=checkbox value="yes"
name="Robin" checked>Robin<br>
<input type=checkbox value="yes"
name="Flash">Flash<br>
</form>
Batman
Superman
Robin
Flash
For check boxes the name changes and the value
stays the same and with radio buttons, the value changes but the
name stays the same. This is because you are allowing for multiple
choices with a check box, whereas a radio button is a one or the
other.

Forms Text Boxes
HTML Result

Text Area
<form method="post" 
action="mailto:xxxxx@xxxx.xxxx">
<textarea name="stuff">
</textarea>
</form>
This is a standard area where unedited text can be sent,
though it is quite possible to add restrictions to modify the box so
that it is more usable by people.

Rows and Columns
<form method="post" 
action="mailto:xxxxx@xxxx.xxxx">
<textarea name="stuff"
rows=10 cols=3>
</textarea>
</form>
As you can see, you can make the text area any shape
you desire, you can make wide ones by modifying the cols tag or
you can make very tall ones by changing the rows allocated.

Wraps - Off
<form method="post" 
action="mailto:xxxxx@xxxx.xxxx">
<textarea name="stuff"
rows=3 cols=15
wrap=off>
</textarea>
</form>
Wrap off is the default wrap status of the text area.
What this means is that the text in the box does not wrap, but it is
sent exactly the way it was typed in.

Wraps - Virtual
<form method="post" 
action="mailto:xxxxx@xxxx.xxxx">
<textarea name="stuff"
rows=3 cols=15
wrap=virtual>
</textarea>
</form>
Wrap virtual means that the text in the box wraps,
but it is sent as one long continuous string.

Wraps - Physical
<form method="post" 
action="mailto:xxxxx@xxxx.xxxx">
<textarea name="stuff"
rows=3 cols=15
wrap=physical>
</textarea>
</form>
Wrap physical means that the text in the box wraps,
and it is sent that way too. This allows for understandable feedback.
One more thing about forms. When you put a mailto form on
your page and someone sends you information, you'll notice that it
is sent with a default subject.

You can change this by editing what's in the <form> tag as follows..

<form method=post action="mailto:xxxx@xxxx.xxx.xx?subject=
The friendly form">

Example
It is now time to incorporate the example again. You have seen forms
broken down into separate sections and explained, now lets use it to
make a feedback page for our example pages.

<html>
<title>Paranormal, UFO's and Mysteries Feedback</title>
<body bgcolor=white text=black link=red vlink=darkred
background="weave.jpg">
<h2><u>Paranormal, UFO's and Mysteries Feedback</u></h2>
<p>
<basefont=4>
<form method=post action="mailto:xxx@xxxx.xx">
<input type=hidden value="Form for example, has some questions on it
as well">
<table>
<tr>
<td>What is your name?</td>
<td><input type=text name="full_name" maxlength=100></td>
</tr>
<tr>
<td>What is your e-mail address?</td>
<td><input type=text name="e_mail" size=30 maxlength=50></td>
</tr>
</table>
<table>
<tr>
<td><input type=checkbox name="name_confirm" checked></td>
<td>Would you like your name posted with your submission?</td>
</tr>
<tr>
<td><input type=checkbox name="email_confirm" checked></td>
<td>Would you like your e-mail address posted with your submission?</td>
</tr>
</table>
Choose the Feedback topic
<select name="submission_type">
<option selected>[none]
<option>Area 51
<option>Ark of Covenant
<option>Millenium
<option>New Topic
<option>General Comments
</select>
<p>
<table>
<tr>
<td colspan=2><font size=+1><u>Please answer the following questions</u>
</font></td>
</tr>
<tr>
<td>Did you like the information supplied on Area 51?</td>
<td><input type=checkbox value="yes" name="A51-y">Yes
<input type=checkbox value="yes" name="A51-n">No</td>
</tr>
<tr>
<td>Did you like the information supplied on the Ark of Covenant?</td>
<td><input type=checkbox value="yes" name="Ark-y">Yes
<input type=checkbox value="yes" name="Ark-n">No</td>
</tr>
<tr>
<td>Did you like the information supplied on the Millennium Propheciest?</td>
<td><input type=checkbox value="yes" name="Mp-y">Yes
<input type=checkbox value="yes" name="Mp-n">No</td>
</tr>
</table>
<p>
<p>
Enter your comments below:
<p>
<textarea name="feedback" rows=6 cols=70>
</textarea>
<p>
<input type=submit>
<input type=reset>
</form>
<p>
<hr>
<p>
<center>
<font size=+2><i>Thank you for your comments!</i></font>
</center><br>
If you're having problems with the form, you can e-mail anything
to <a href="mailto:xxxxx@xxxx.xxx.xx">xxxxxx@xxxx.xxx.xx</a>
<p>
<a href="back.to.main.page">Return to Main Page</a></font>
</body>
</html>

The form page is normally a new page, you can either use the above code
to make a new page (form.htm), or you could just apply the important pieces of code
to a pre existing page. To speed it up, you can cut and paste
the code. After you have done all of this, click
here (Form)
to compare your work to the example provided.

A very important thing to note is that, there is no main page for the
link back. By now you should be able to make the link back to main
yourself

Click on Advanced Lesson 9 to continue, or click here (Top) to return to the top of document