spacer

Webref WebRef   Sitemap · Experts · Tools · Services · Newsletters · About i.com

home / web / articles / htmlform / syntax

Form Syntax

Developer News
Eclipse Helios Update Brings New PHP Tools
Internet Explorer 9 Ups Standards Support
JBoss Portal 5 Release Easier to Use

Programming with HTML Forms

Before a forms application can be described, the HTML features for defining forms need to be reviewed.

A form begins with:

    <FORM ACTION="URL address of application" METHOD="POST">

and ends with:

    </FORM>

The METHOD attribute specifies how the data entered in the various fields of the form is transmitted to the application. It is best to use the POST method, since the data is then sent to the standard input of the application, as a string of the form:

    name=value&name=value&...

name is the name of the form's data entry field, while value is its associated data.

The other method for sending data is GET. This causes the string to arrive at the server in the environment variable QUERY_STRING, which may result in the string being truncated if it exceeds the shell's command line length. For that reason, GET should be avoided.

A form can contain 8 types of data entry field:

  • single line text entry fields
  • check boxes
  • radio boxes
  • hidden fields
  • password fields
  • selection lists
  • multi-line text entry fields
  • submit and reset buttons

Single line text entry fields, hidden fields, password text fields, check boxes and radio boxes are specified using the same basic HTML syntax:

    <INPUT TYPE="field-type" NAME="Name of field" VALUE="default value">

field-type can be either: text, checkbox, radio, hidden, or password.

For a check box or radio button, the VALUE field specifies the value of the field when it is checked; unchecked check boxes are disregarded when name=value substrings are being posted to the application.

If several radio buttons have the same name then they act as a one-of-many selection: only one of them can be switched 'on', and so have its value paired with the name.

A hidden text field does not appear on the form, but can have a default value which will be sent to the application.

A password text field will echo *'s when a value is typed into it.

A selection list is specified using:

    <SELECT NAME="list title"> <OPTION>first option <OPTION>second option : </SELECT>

The option chosen will become the value associated with the selection list's name. It is also possible to include the attribute MULTIPLE after the NAME string to allow multiple selections. This maps to multiple name=value substrings, each with the same name.

A multi-line text entry field has the form:

    <TEXTAREA NAME="text area name" ROWS=no-of-rows COLS=no-of-columns> Default text goes here </TEXTAREA>

The submit button causes the document to collect the data from the various form fields, pair it with the names of the fields, and post it to the application. The reset button resets the fields to their default values. Button syntax is:

    <INPUT TYPE="submit" VALUE="text on button"> <INPUT TYPE="reset" VALUE="text on button">

Thirteen form examples are accessible through:

overview.html also contains more details on the syntax of form fields.

Comments are welcome

Copyright 1996 Andrew Davison and

webref The latest from WebReference.com Browse >
Flashmaps' DynamicLocator: Interactive Maps for Small Areas · Flashmaps' AreaSelector: Interactive Maps for Wide Areas · The DB Mapper: Interactive Street-level Maps of U.S. and Canada
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
MS Access and MySQL · Cisco AutoQoS: VoIP QoS for Mere Mortals · While VoIP Adoption Explodes in Enterprise, Carrier Spending Lags

Created: Apr. 26, 1996
Revised: May 7, 1996

URL: http://webreference.com/htmlform/syntax.html