HTML formmethod Attribute
The HTML formmethod Attribute is used to define the HTTP method that is used to send form data while submitting the form. GET and POST are the two well-known HTTP methods. This attribute overrides the feature of the method attribute of the <form> element.
- get: It is a default value. In the GET method, after the submission of the form, the form values will be visible in the address bar of the new browser tab. It has a limited size of about 3000 characters. It is only useful for non-secure data but not for sensitive information.
- post: In the post method, after the submission of the form, the form values will not be visible in the address bar of the new browser tab as it was visible in the GET method. It appends form data inside the body of the HTTP request. It has no size limitation. This method does not support bookmarking of the result.
Example 1: Below code demonstrates the use of formmethod attribute in the HTML <input type=”submit”> control. Refer to the output given below for a better understanding. Notice the address bar of the new web page on clicking “Submit normally” and “submit using POST method”. Both are different, one showing the user details and the latter hiding all the user details.
Example 2: The following example demonstrates the HTML formmethod=”get” attribute using the button element. It submits the user entries to the “getDetail.php” PHP file. When the user clicks “Submit using get method”, the values are submitted to the PHP file, notice the address bar in the below output.
- Google Chrome 9.0
- Internet Explorer 10.0
- Firefox 4.0
- Safari 5.1
- Opera 10.6