HTML Tutorial - HTML Forms








Forms are the HTML mechanism for gathering input from the user.

To create a basic form, you need three elements: the form, input, and button elements.

The following table shows an HTML document that contains a simple form.

<!DOCTYPE HTML>
<html>
<body>
  <form method="post" action="http://example.com/form">
    <input name="name" />
    <button>Submit Vote</button>
  </form>
</body>
</html>

Click to view the demo





Form

The form element, with local attributes: action, method, enctype, name, accept-charset, novalidate,target, autocomplete, ,creates a form in an HTML page.

The novalidate and autocomplete attributes are new in HTML5.

Form HTTP method

The method attribute specifies which HTTP method will be used to send the form data to the server.

The allowed values are get and post, which correspond to the HTTP GET and POST methods.

The default value for method attribute is get.

The following code set the post value for the form.

<form method="post" action="http://example.com/form">

For GET requests, you can make the same request many times.

GET requests should be used for all read-only information retrieval.

POST requests are for unsafe interactions, where the act of submitting the data changes some kind of state.

POST requests should be used for any operation that changes the application state.