demosthenes.info

I’m Dudley Storey, the author of Pro CSS3 Animation. This is my blog, where I talk about web design and development with , and . To receive more information, including news, updates, and tips, you should follow me on Twitter.

featured articles

popular favourites

The Form Tag

Unfortunately when the HTML for forms was being designed consistency was not a high priority. You will find that most form-specific tags are <input> tags, but there are several notable exceptions.

The main points to remember about forms are as follows:

  • a form starts with a <form> tag and closes with a matching </form> tag. Form elements (text fields, drop-down menus, etc) are only valid between the opening and closing tag in XHTML. In HTML5 you may put a form element, such as an input, anywhere on the page, with or without a surrounding form tag.

  • The form tag has two attributes that are typically added: method and action.

  • A form’s method is the way the submitted data is passed to whatever will be processing it (a CGI script, a PHP script, etc). Ninety percent of the time this method will be post. Alternatively, the get method appends the data to the URL itself when it is submitted, which is obviously less secure (but helpful, if you are interested in debugging a form or bookmarking a page created through a form decision).

  • The action attribute of the form tag tells the form where to submit its data to. If a CGI script written in Perl was processing the data, the action attribute would typically be set to something like cgi-bin/form.pl. If a PHP script, it would be something like formhandler.php.

The first step in creating our form is the opening and closing <form> tags, with the correct attributes:

  1. <form method="post" action="formhandler.php">
  2. </form>

XHTML requires a fieldset tag immediately inside the form tag. fieldset is a container element inside the form. Think of filling out your tax form at the end of each year: each major section of the form (personal information, employer, income) is divided into a seperate box. fieldset is that box in the context of a form. A form may contain multiple fieldsets.

Immediately inside the fieldset you should enter a <legend> tag, with appropriate content. The <legend> is essentially the label for the entire fieldset, and typically indicates the purpose of that section. (“Personal information”, “Mailing Address”, “Billing Info”, etc).

fieldset is optional in HTML5, but it is a good idea to use it.

You must be signed up in order to leave comments.

web developer guide

featured comment

by Aisling Brock in New Business Card Design

what i'm reading

A Feast for Crows: A Song of Ice and Fire: Book Four
A Feast for Crows: A Song of Ice and Fire: Book Four

what i'm watching

Prometheus: Collector's Edition (Bilingual) [Blu-ray 3D + Blu-ray + DVD + Digital Copy]
Prometheus: Collector's Edition (Bilingual) [Blu-ray 3D + Blu-ray + DVD + Digital Copy]

what i'm playing

Borderlands
Borderlands

what i'm hearing

Planets
Planets

blogs

podcasts

no ads ever

This blog is free of advertising, and always will be.

creative commons licensed

The content of this blog is free to use in whatever way you wish under the Creative Commons license.