Form Attributes

Attributes to Use with the <form> tag
Attribute Purpose and Syntax Values
method Determines how the information from the form will be sent to the server.
<form method="GET" or "POST">

You have two choices for this attribute, POST or GET. The GET method adds the information provided by the user to the actual web page URL. The CGI script then extracts this data from the appended URL. The advantage of this method is that you can bookmark the URL and save the data with it. The disadvantage is the amount of data you can send and the fact that the data is clearly visible in the address bar. This method is not suitable for sensitive data.

The POST method sends a data file to the server. The data file that is sent contains a name or label and a value for each piece of information that the user enters. The name of a data field must match the name in the CGI script so keep that in mind when creating forms. The advantage of the POST method is that the data is not clearly visible and you are not limited in the amount of data you can send.

action Indicates which file on the server will handle the information sent from the form,
e.g., <form action="filename.php">

If the web page containing the form is located on the server running the CGI script then you would include the path to that file, e.g. scripts/php/filename.php

If the action script is located on another server then you would use the absolute path to the file: http://www.techdodge.com/scripts/php/filename.php.

Attributes to Use with the <fieldset> tag
Boxes in sections of a form when you want to group several form items together. Good to use when you have a long form with many sections. There are no attributes associated with this tag but the <legend> tag is used to place text in the border of the fieldset.

<fieldset>

<legend align="left">Please complete this section of the form first</legend>
Your form elements would go here.
</fieldset>

Attributes to Use with the <legend> tag

Attribute Purpose and Syntax Values
align Determines where the text is located on the top line of the border of the fieldset.
<legend align="center">

Allows you to align the text at the left, center or right side at the top of the fieldset.

Attributes to Use with the <input> Tag.
Used to create Text boxes, Password boxes, Radio Buttons and Checkboxes.
Attribute Purpose and Syntax Values
type Produces a text box for entering one line of text,
e.g., <input type="text">

text - produces a single line text box
password - same as text box but the letters are hidden
radio - produces radio buttons of which only one can be selected at a time.
checkbox - produces a checkbox which allows multiple selections

name This is the label that is passed to the CGI script and identifies what information is contained in the input value,
e.g., <input type="text" name="title">
Here are some examples of names that you might use, title, age, address. Each of these names would then have a matching value that is provided by the user of the form.
size Sets the size of the text box,
e.g., <input size="30">
Size here is measured in characters.
maxlength Defines the maximum number of characters allowed in the field,
e.g., <input maxlength="45">
Maximum number of characters allowed in this field.
name
(when used with radio buttons)
Creates a set of radio buttons as long as they have the same name value,
e.g., <input type="radio" name="age">
Every radio button with the same name value (age in this example) would be part of a radio set. Only one radio button from a radio set can be selected at a time.
value
(used with radio buttons and check boxes)
Tells the form what information to send to the server when that button is selected,
e.g., <input type="radio" name="age" value="40">
If this radio button is selected send an age value of 40 to the server. Each radio button should have its own unique value. The same is true of checkboxes.

checked
(used with radio buttons and check boxes)

When the form page comes up this radio button or check box will already be checked,
e.g., <input type="radio" checked="checked">

e.g., <input type="checkbox" checked="checked">

Allows you to pre select what buttons or boxes are checked but the user can change these. Acts as a default value.
submit

Used to send the form data to the server.

e.g., <input type="submit" value="Send Info">

The value for this attribute is the text that will appear on the button, in this case "Send Info".
reset e.g., <input type="reset"> Clears the form of all current data

Attributes to Use with the <textarea> Tag.
Creates a multiple line text area.
Attribute Purpose and Syntax Values

 

name

 

 

This is the label that is passed to the CGI script and identifies what information is contained in the input value,
e.g., <textarea name="comments">

 

Here are some examples of names that you might use, description, comments, feed back.. Each of these names would then have a matching value that is provided by the user of the form.

rows Determines the height of the text area.
e.g., <textarea rows="8">
The number entered here is the height of the text area in rows. The default is 4.
cols Determines the width of the text area.
e.g., <textarea rows="35">
The number entered here is the width of the text area in characters. The default is 40.
wrap Automatically wraps the text within the margins of the text area.
e.g., <textarea wrap>

This is simply and on or off switch. IE will automatically wrap text, Netscape will not.

Attributes to Use with the <select> Tag.
Used to create Menu lists

Attribute Purpose and Syntax Values

 

name

 

 

This is the label that is passed to the CGI script and identifies what information is contained in the input value,
e.g., <select name="comments">

 

The name will identify the information that is being sent to the CGI script.

size Determines the number of options that should be initially visible in the menu.
e.g., <select size="8">
 
multiple Allows multiple items to be selected from the menu.
e.g., <select multiple>
 

Attributes to Use with the <option> Tag.
This tag is used with the <select> tag to create the individual items in the pull down menu or list box.

Attribute Purpose and Syntax Values

 

selected

 

 

Makes the option listed the default value, already selected when the page opens.
e.g., <option selected>

 

There are no values associated with this attribute.

value
Tells the form what information to send to the server when that menu item is selected,
e.g., <option value="Alaska">
If this menu item is selected then the browser will send a a value of "Alaska" to the server. Each option should have its own unique value.