HTML | PHP | Forum

HTML <form> tag


<form> - </form>

Definition and Usage

The FORM tag acts as a container for controls. It specifies:

  • The layout of the form (given by the contents of the element).
  • The program that will handle the completed and submitted form (the action attribute). The receiving program must be able to parse name/value pairs in order to make use of them.
  • The method by which user data will be sent to the server (the method attribute).
  • A character encoding that must be accepted by the server in order to handle this form (the accept-charset attribute). User agents may advise the user of the value of the accept-charset attribute and/or restrict the user's ability to enter unrecognized characters.

A form can contain text and markup (paragraphs, lists, etc.) in addition to form controls.

Required Attributes

Attribute Value Description
action URI An URL, a CGI script or JAVA servlet that defines where to send the data when the submit button is pushed

Optional Attributes

Attribute Value Description
accept list of contenttypes This attribute specifies a comma-separated list of content types that a server processing this form will handle correctly. User agents may use this information to filter out non-conforming files when prompting a user to select files to be sent to the server
accept-charset charset_list A comma separated list of possible character sets for the form data. The default value is "unknown"
enctype mimetype The mime type used to encode the content of the form
method get
This attribute specifies which HTTP method will be used to submit the form data set

get: With the HTTP "get" method, the form data set is appended to the URI specified by the action attribute (with a question-mark ("?") as separator) and this new URI is sent to the processing agent.

post: With the HTTP "post" method, the form data set is included in the body of the form and sent to the processing agent.

name form_name Defines a unique name for the form
target _blank

Defines the location of the target URI.

  • _blank renders the response in a new, unnamed window
  • _self renders the response in the current frame
  • _parent renders the response in the immediate frameset parent
  • _top renders the response in the full, unframed window

Standard Attributes

id, class, title, style, dir, lang, xml:lang

For a full description, go to Standard Attributes.

Event Attributes

onsubmit, onreset, onclick, ondblclick, onmousedown, onmouseup, onmouseover, onmousemove, onmouseout, onkeypress, onkeydown, onkeyup

For a full description, go to Event Attributes.


Source Output
<form action="test.htm" method="GET" target="_new">
<p><input type="text" name="email" size="10" value="email@">    
<input type="submit" value="Subscribe" name="B1"></p>



Learn HTML
HTML Tutorial

HTML Reference
HTML by function
HTML by Alphabet

HTML events
HTML attributes
HTML color names

<h1> to <h6>


Copyright 2005-8 Sunilcare.  All Rights Reserved.
Comments or suggestions? Contact us.About us