HTML form - how to use <form> tag

The HTML <form> tag is used to define a form through which users can submit data back to the server. An example of a form would be a form to collect contact information.

The form tag usually contain a number of input tags, text area tag and a submit or reset button.

Attributes

The form tag supports the global and event attributes.

accept-charset
Defines the character encoding for submitting form data
action
Defines the URL where the form data should be submitted to. The URL can be both absolute or relative.
autocomplete
Defines whether autocomplete feature should be turned on or off. Acceptable values are
  • on
  • off
enctype
Defines how to encode the form data for submitting to the server.
The form data can be encoded in
  • application/x-www-form-urlencoded
  • multipart/form-data
  • text/plain
method
Defines the HTTP method to use for submitting the form data.
The form methods can be GET, POST, PUT, DELETE, etc.
name
Define a name for the form
novalidate
Defines that the form should not be validated when submitted
target
Defines where to display the response from the server after submitting the form. The response can be displayed in a new window or current window.

Examples:

<form action="form.aspx" method="get" autocomplete="on"> <fieldset> <legend>Form data:</legend> <!--text field--> First Name: <input type="text" id="tfirstName" placeholder="enter first name" /><br /> Last Name: <input type="text" id="tlastName" placeholder="enter last name" /><br /> Email: <input type="email" id="temail" placeholder="enter email" /><br /> <!--submit button--> <input type="submit" value="Submit" /> <!--reset button--> <input type="reset" value="Reset Form" /> </fieldset> </form>

Related HTML tags

The form tag is usually used with the following tags. The various tags basically allows users to submit form data using different fields

Useful Links