Syntax:
The FORM is a two-sided coin. The HTML portion displays fields in the browser that allow the user to fill in information and send it back to you. However, once the information is submitted, doing anything with it requires programming on the server. The server side programming is beyond the scope of this course and will not be covered here. Check with your ISP, many already have the needed programs set up for you. This document will discuss the HTML side of setting up a form.
Attribute | |||||||||
---|---|---|---|---|---|---|---|---|---|
Action | This specifies the URL of the script that will be used to process the information that is submitted. | ||||||||
Enctype | This is set to the MIME type for the file being uploaded. It does not create the field for the file name but merely tells the browser what to expect. | ||||||||
Method | This specifies the HTTP method to use when passing data to the
script. Method can take the value of Get or Post.
If no method is specified, the default GET is used.
|
Named Input Fields
The tags that create the input fields produce the fields only. You will need to include some kind of descriptive text that tells the user what information to enter.
The <INPUT> Tag
CheckBox |
|
Radio |
Radio Buttons are grouped together by giving all the buttons within
the group the same name.
|
Hidden | A hidden field does not appear on the form and is used to send
data to the server without the intervention of the user. This
can be used, for example, to carry data from one form to another
when you have a long form that you want to break up into several
smaller forms and still keep all the user's input together.
Another common use is if you want a single general script to
process data from several different forms; the script will need
to know which form the data came from in order to process it
correctly.
|
Multiple Line Text Input
Menus
SELECT Attributes | |
---|---|
Name | Specifies the name of the field that is passed to the script for processing. |
Size | Optional. Specifies the width of the control on the screen in characters. |
Multiple | Optional. Specifies that more than one option may be selected. |
OPTION Attributes | |
Selected | Optional. Specifies that the option is selected by default. |
Action Buttons
Attribute | Description | ||||
Type | Determines the type of action performed when the user clicks on
the button.
| ||||
Value | Set the text that appears on the button. |
Using Images as Submit Buttons
You can also use an image file as a custom Submit button. Again the key is the INPUT tag. You cannot, however, add text to an image button using the INPUT tag as you can with the standard button; you will have to use a graphics manipulation package to add text to the image itself. The syntax for this tag is:
The SRC and optional ALIGN attributes have exactly the same effect as they do with the <IMG> tag discussed earlier in the section on graphics.
The NAME attribute of the Submit Buttons
The SUBMIT button also has a NAME attribute. This theoretially makes it possible to have more than one Submit button on the same form. Since multiple Submits are not standardized, the handling of this situation is not supported by all browsers and therefore the results you will get are not going to be consistent. I recommend that you avoid the use of multiple SUBMIT buttons until their use has been standardized.
Putting it all Together
Now that we have seen what goes into building a form, lets put one together. Suppose you want your customers to enter their contact information and the configuration of their computer plus give them the opportunity to enter comments. The source document for this form might look like this:
<H2>SAMPLE FORM</H2>
<FORM>
Name <INPUT TYPE="text" NAME="name" SIZE=31>
Email <INPUT TYPE="text" NAME="mail"
SIZE=19><BR>
Address <INPUT TYPE="text" NAME="add1"
SIZE=60><BR>
<INPUT TYPE="text" NAME="add2"
SIZE=60><BR>
City <INPUT TYPE="text" NAME="city" SIZE=27>
St <INPUT TYPE="text" NAME="st" SIZE=6>
Zip <INPUT TYPE="text" NAME="zip"
SIZE=16><BR>
<HR> <BR>
Computer
<SELECT NAME="brand">
<OPTION>Generic</OPTION>
<OPTION>IBM</OPTION>
<OPTION>Compaq</OPTION>
<OPTION>Dell</OPTION>
<OPTION>Gateway</OPTION>
</SELECT>
<INPUT TYPE="checkbox">Sound Card
<INPUT TYPE="checkbox">Modem
<INPUT TYPE="checkbox">Printer
<INPUT TYPE="checkbox">CD-ROM<BR>
RAM
<INPUT TYPE="radio"
NAME="ram">8Mb
<INPUT TYPE="radio"
NAME="ram">16Mb
<INPUT TYPE="radio"
NAME="ram">32Mb
<INPUT TYPE="radio"
NAME="ram">64Mb
HD
<INPUT TYPE="radio"
NAME="hdd">2Gb
<INPUT TYPE="radio"
NAME="hdd">4Gb
<INPUT TYPE="radio"
NAME="hdd">6Gb
<INPUT TYPE="radio"
NAME="hdd">8Gb
<P>
Comment
<TEXTAREA NAME="comment" ROWS=5 COLS=55></TEXTAREA>
<P>
<INPUT TYPE="submit" VALUE="Send">
<INPUT TYPE="reset" VALUE="Clear">
</FORM>
The resulting form will be rendered by the browser to look like this:
Wow! After all that work, that sure is an UGLY form. If you will recall from the first part of this course I mentioned that HTML ignores white space. Since the text used to label the form controls is all different lengths, the controls will be placed on the screen in different positions resulting in the haphazard appearance of the form shown above. So what can you do about it? In our previous discussion of tables, I mentioned that one of the things that can be placed in a table cell is a form control. The code below combines a table with the same form code listed above.
<TABLE>
<FORM>
<TR><TH COLSPAN=6 ALIGN="left"><H2>SAMPLE
FORM 2</H2>
<TR>
<TD>Name
<TD COLSPAN=2>
<INPUT TYPE="text"
NAME="name" SIZE=31>
<TD>Email
<TD COLSPAN=2>
<INPUT TYPE="text" NAME="mail" SIZE=19>
<TR>
<TD>Address
<TD COLSPAN=5><INPUT TYPE="text"
NAME="add1" SIZE=60>
<TR>
<TD>
<TD COLSPAN=5><INPUT TYPE="text"
NAME="add2" SIZE=60>
<TR>
<TD>City
<TD><INPUT TYPE="text"
NAME="city" SIZE=27>
<TD>St
<TD><INPUT TYPE="text"
NAME="st" SIZE=6>
<TD>Zip
<TD><INPUT TYPE="text"
NAME="zip" SIZE=16>
<TR>
<TD COLSPAN=6><HR>
<TR>
<TD>Computer
<TD>
<SELECT NAME="brand">
<OPTION>Generic</OPTION>
<OPTION>IBM</OPTION>
<OPTION>Compaq</OPTION>
<OPTION>Dell</OPTION>
<OPTION>Gateway</OPTION>
</SELECT>
<INPUT TYPE="checkbox"
NAME="sound">Sound Card
<TD COLSPAN=2><INPUT TYPE="checkbox"
NAME="modem">Modem
<TD COLSPAN=2><INPUT TYPE="checkbox"
NAME="print">Printer
<INPUT TYPE="checkbox" NAME="cdrom">CD-ROM
<TR>
<TD COLSPAN=2>RAM
<INPUT TYPE="radio"
NAME="ram">8Mb
<INPUT TYPE="radio"
NAME="ram">16Mb
<INPUT TYPE="radio"
NAME="ram">32Mb
<INPUT TYPE="radio"
NAME="ram">64Mb
<TD COLSPAN=4>HD
<INPUT TYPE="radio"
NAME="hdd">2Gb
<INPUT TYPE="radio"
NAME="hdd">4Gb
<INPUT TYPE="radio"
NAME="hdd">6Gb
<INPUT TYPE="radio"
NAME="hdd">8Gb
<TR><TD COLSPAN=6>
<TR>
<TD VALIGN="top">Comment
<TD COLSPAN=5>
<TEXTAREA NAME="comment" ROWS=5 COLS=55>
</TEXTAREA>
<TR><TD COLSPAN=6>
<TR VALIGN=top>
<TD COLSPAN=3><INPUT TYPE="submit"
VALUE="Send">
<TD COLSPAN=3><INPUT TYPE="reset"
VALUE="Clear">
</FORM>
</TABLE>
The result is that you can use the columns of the table to align the form controls to a more aesthetically pleasing appearance. Note that the table's border is turned off so that nobody will know that you 'cheated'.