HTML form attribute

HTML form attribute associates input element with a specific form.

Email: <input type="email" name="cemail" form="cform">

<form action="files/form.php" method="post" id="cform">
 Candidate name: <input type="text" name="cname">
 Password: <input type="password" name="pass">
  <input type="submit" name="submit">
</form>
</>
Email:
Candidate name:
Password:

Attribute values

All possible values of form attribute

The value of form attribute is the id of the <form> element. Although 'email' is outside the form but still a part of the form because of this attribute.

Related Tags

The tags that support form attribute

<button> tag

button element defines a button labeled by the content. form attribute is also applicable on the button element.

<form action="files/formbutton.php" method="post" id="data">
 <input type="text" name="guest-name" >
</form>

<button type="submit" name="send" form="data">Send</button>
Try</>

<fieldset> tag

fieldset element encloses a form structure in a box. It also supports the form attribute.

<input> tag

input tag defines an input field where a user can enter the required information. input tag supports form attribute.

<label> tag

label tag is used to write captions. for attribute is applicable on the label element.

<select> tag

select tag offers different options in the form of drop down list.

<select name="sl" form="data"> 
  <option> Australia
  <option> Egypt
  <option> Algeria
  <option> India
</select> 

<form action="files/formselect.php" method="post" id="data">
 <input type="submit" name="select">
</form>
Try</>

<textarea> tag

textarea tag element defines multi line editable area of text.

<textarea name="ta" form="data"> </textarea>
<form action="files/formtextarea.php" method="post" id="data"> 
 <input type="submit" name="send">
</form>
Try</>


Was this article helpful?