method (HTML attribute)

Spec
Depr. Version
No HTML 2
Browser support (more…)
IE5.5+ FF1+ SA1.3+ OP9.2+ CH2+
Full Full Full Full Full

Syntax

method=" { get | post } "

Description

The form’s method attribute instructs the browser to send data on to the page or script (identified in the action attribute) either as information appended in the URL, using "get" (which is useful for form submissions for which you subsequently want to bookmark the results), or packaged as an HTTP post transaction, using "post".

The "get" method has a couple of shortfalls that you should be aware of. Firstly, there’s a limit to how much data you can place in a URL (it varies between browsers, and also between servers), and as a result, you can’t rely on the information to be correctly transferred or processed. Secondly, passing sensitive information in this way is a security issue, yet passwords are all too often passed in this way (a crazy practice—anyone could look over the user’s shoulder and read the password).

The "post" method may require a little more processing on the server, and form submissions made in this way can’t be bookmarked. However, the "post" method is a more robust solution, and doesn’t suffer the size limitations that "get" does.

Example

Here, we use the method attribute to tell the browser to append data to the URL via the "get" method:
<form action="address.php" method="get">
  <div>
    <label for="txtname">Full Name:</label>
    <input type="text" name="txtname" id="txtname"/></span>
  </div>
  <div>
    <label for="txtcontacttel">Contact Tel:</label>
    <input type="text" name="txtcontacttel" id="txtcontacttel"/>
  </div>
  <div>
    <input type="submit" name="cmdSubmit" id="cmdSubmit"
        value="Send personal details"/>
  </div>
</form>

Value

This attribute accepts "get" and "post" values only.

Compatibility

Internet Explorer Firefox Safari Opera Chrome
5.5 6.0 7.0 8.0 1.0 1.5 2.0 3.0 3.5 1.3 2.0 3.1 4.0 9.2 9.5 10.0 2.0
Full Full Full Full Full Full Full Full Full Full Full Full Full Full Full Full Full

It causes no compatibility issues, and has excellent support across all tested browsers.

User-contributed notes

Related Products