HTML <form> Tag
<form name="myForm" action="/resources/html-forms-action.cfm">
<fieldset>
<legend>Name Details</legend>
<p><label>First Name: <input name="fName"></label>
<p><label>Surname: <input name="sName"></label>
<p><label>Preferred Name: <input name="pName"></label>
</fieldset>
<fieldset>
<legend>Gender</legend>
<p><label><input type="radio" name="gender" value="male"> Male</label>
<p><label><input type="radio" name="gender" value="female"> Female</label>
</fieldset>
<button>Submit</button>
</form>
The above example demonstrates usage of the <form>
element.
The <form>
element represents a form in an HTML document. A form is a collection of form-associated elements, some of which can represent editable values that the user can submit. Once submitted, a script on the server can process the form.
For example, it could send an email, insert data into a database, provide feedback to the user, and more. Such a script could do all of these things or none of them. However, the <form>
element is not involved in any of that. It simply represents the collection of form-associated elements that are displayed to the user.
Form-Assocated Elements
Form-associated elements mean that the element can have a form owner. The form-associated elements are:
A form can contain other elements too — it doesn't have to be a form-associated element in order to be nested between the <form>
and </form>
tags. For example, you can include <p>
, <div>
and <span>
elements within a form.