Input Form Attributes


Lesson 31 of 58

HTML input elements have special attributes that let you control how they interact with forms. These “form attributes” allow you to do things like place inputs outside a form, override form actions, or skip validation for specific buttons.


The form Attribute

The form attribute lets you place an input field outside of a form tag, but still have it belong to that form. The value must match the id of the form.

Form Attribute Example

The formaction Attribute

The formaction attribute lets you send the form data to different URLs depending on which button the user clicks. This overrides the form’s main action attribute.

Formaction Attribute Example

The formenctype Attribute

The formenctype attribute specifies how form data should be encoded when submitted. This is especially important for file uploads. It overrides the form’s enctype attribute.

Formenctype Attribute Example

The formmethod Attribute

The formmethod attribute lets you override the form’s HTTP method. One button can use GET while another uses POST. This overrides the form’s method attribute.

Formmethod Attribute Example

The formtarget Attribute

The formtarget attribute specifies where to display the response after submitting the form. You can open the result in a new tab or the same window. This overrides the form’s target attribute.

Formtarget Attribute Example

The formnovalidate Attribute

The formnovalidate attribute lets you skip validation for a specific submit button. This is useful when you want a “Save Draft” button that does not require all fields to be valid. This overrides the form’s novalidate attribute.

Formnovalidate Attribute Example

The novalidate Attribute (Form Level)

The novalidate attribute is applied to the <form> element itself. It turns off ALL validation for the entire form. No fields will be validated before submission.

Novalidate Attribute Example

Quick Summary

  • form – Connect an input outside a form to that form using the form’s ID
  • formaction – Override where the form data is sent (different URLs for different buttons)
  • formenctype – Override how form data is encoded (important for file uploads)
  • formmethod – Override the HTTP method (GET vs POST)
  • formtarget – Override where the response opens (same tab or new tab)
  • formnovalidate – Skip validation for a specific submit button (like a “Save Draft” button)
  • novalidate – Skip validation for the entire form (put on the form tag itself)

What Just Happened? Let Me Explain

  • These form attributes give you fine-grained control over how your forms behave. You can have different buttons do different things.
  • The form attribute is very useful when you want to place inputs outside the form tag for layout reasons, but still have them submitted.
  • The formaction attribute is great for having “Save Draft” vs “Publish” buttons that send data to different server scripts.
  • The formenctype="multipart/form-data" is REQUIRED when you are uploading files. Without it, the file data will not be sent correctly.
  • The formnovalidate and novalidate attributes are useful for development or for saving drafts, but be careful: never trust client-side validation alone. Always validate on the server too.
Tip: These form override attributes only work on submit buttons. They will not work on regular buttons or other input types.

HTML Form Input Attributes Reference

Attribute Description
formSpecifies which form the input belongs to (by form ID)
formactionOverrides the form’s action URL (for submit buttons)
formenctypeOverrides how form data is encoded (for submit buttons)
formmethodOverrides the HTTP method (GET or POST) for submit buttons
formtargetOverrides where to display the response (for submit buttons)
formnovalidateSkips validation for a specific submit button
novalidateSkips validation for the entire form (attribute on <form>)
Note: The formaction, formenctype, formmethod, formtarget, and formnovalidate attributes only work on input types submit and image.

Lesson 31 of 58