← Back to HTML Course | Chapter 5: Forms | Lesson 6 of 7

HTML Input Form Attributes

Imagine filling out a paper job application. The main form packages your basic details and sends them to the HR office. However, at the bottom of the page, there is a specialized button that packages your file resume and sends it directly to the engineering team instead. HTML input form attributes are those specialized controls. They do not change what input fields are displayed on your page, but they allow specific buttons or fields to override the settings of the parent form tag. You can use these attributes to make individual buttons submit data to different server endpoints, change request methods, or bypass validation checks on the fly.

The form Attribute

By default, input fields must be placed inside a form container to submit their data. The form attribute allows you to place input fields anywhere on your page (even outside the form tag) and link them to a specific form using its unique ID.

Note: Use the form attribute to build complex, creative layouts without being restricted by form tag nesting.

Warning: Ensure the form attribute value matches the target form's ID exactly, or the data will fail to submit.

Example: The form Attribute

markup
<form id="myForm" action="/submit"></form>
<input type="text" name="username" form="myForm">

Overriding Endpoints with formaction

The formaction attribute is used on submit buttons to override the default action URL of the parent form tag. This allows you to create different buttons that send the exact same form data to different server endpoints.

Note: Use the formaction attribute to create separate 'Save Draft' and 'Publish Live' buttons on the same form.

Warning: Make sure your formaction URLs are completely correct and secure, or your form submissions will fail.

Example: Overriding Endpoints with formaction

markup
<form action="/save">
  <button type="submit" formaction="/save-draft">Save Draft</button>
  <button type="submit" formaction="/publish">Publish</button>
</form>

Changing Data Formats with formenctype

The formenctype attribute is used on submit buttons to override the default encoding type of the parent form tag. This is incredibly useful when you want a specific button to upload files (which requires multipart/form-data) while keeping other fields as standard text.

Note: Use the formenctype attribute to handle both text fields and file uploads on the same form dynamically.

Warning: Failing to specify the multipart/form-data encoding type on file uploads will cause your file transfers to fail.

Example: Changing Data Formats with formenctype

markup
<form action="/submit">
  <input type="file" name="file">
  <button type="submit" formenctype="multipart/form-data">Upload</button>
</form>

Changing Request Methods with formmethod

The formmethod attribute is used on submit buttons to override the default HTTP request method (GET or POST) of the parent form tag, allowing you to change how your data is transmitted on the fly.

Note: Use formmethod to quickly toggle between public GET requests and secure POST requests.

Warning: Never use the GET method to transmit sensitive user data, as they will be displayed openly in the browser address bar.

Example: Changing Request Methods with formmethod

markup
<form action="/submit" method="get">
  <button type="submit" formmethod="post">Submit Securely</button>
</form>

Bypassing Form Validation with formnovalidate

By default, browsers perform basic validation checks on form fields before submitting. The formnovalidate attribute is used on submit buttons to bypass these native checks, allowing you to save drafts or cancel actions even if required fields are left blank.

Note: Use the formnovalidate attribute on 'Save Draft' buttons so users can save their progress without filling in all required fields.

Warning: If you bypass validation, you must handle necessary checks on your server to prevent submitting empty forms.

Example: Bypassing Form Validation with formnovalidate

markup
<form action="/submit">
  <input type="email" required>
  <button type="submit" formnovalidate>Save Draft</button>
</form>
Common Mistakes
  1. Failing to match the form attribute value with the target form's ID exactly, resulting in broken submissions.
  2. Using the public GET method on overridden buttons designed to transmit sensitive user passwords.
  3. Disabling browser validation using formnovalidate on primary submission buttons without writing backup validation scripts.
Chapter Summary
  • Input form attributes allow individual buttons or fields to override the default settings of the parent form tag.
  • Link external input fields to a form anywhere on your page using the form attribute matched to the form ID.
  • Use formaction, formenctype, formmethod, and formnovalidate attributes on submit buttons to override the target URL, encoding type, request method, or validation settings dynamically.
Browser Support

Standard input form override attributes are supported natively by all modern web browsers.

🔒

Chapter Quiz — Complete all 7 topics to unlock

0/7 topics done

Complete these topics first:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.