Form
form attribute
The form
attribute in HTML links an input or form element to a specific <form>
elsewhere in the document. This allows the element to be included in the form submission, even if it's not nested within the <form>
tags.
Syntax
<tagname form="form-id">
The form
attribute contains the id
of the form it is associated with. When the form is submitted, the input element with this attribute is treated as if it were inside the form, ensuring it's included in the submission.
Example
<form id="myForm" method="get">
<label for="name">Name:</label>
<input type="text" id="name" name="name">
<input type="submit" value="Submit">
</form>
<!-- This input is visually separated from the form above but is still associated with it -->
<input type="email" id="email" name="email" form="myForm" placeholder="Enter your email">
action
attribute is not provided, the form will submit to the same URL from which it was loaded.Values
Applies To
The form
attribute can be used on the following html elements.
Conclusion
The form
attribute in HTML connects form elements to a specific form elsewhere in the document, allowing for more flexible layout and streamlined form submissions. It lets elements outside the form tags be included in the submission. This is particularly helpful when designing layouts where inputs are visually separated but logically belong to the same form.
Specific
Specific attributes in HTML control element behavior, improving interactivity and usability. They include Form, Input, and Media attributes, each serving a unique role.
accept-charset
The accept-charset attribute in HTML tells the server which character encodings are supported for form data. When the form is submitted, the browser uses this attribute to encode the data before sending it.