HTML formaction Attribute

Description

The formaction attribute in HTML is an attribute that can be used within <button> or <input type="submit"> elements to specify the URL of the file that will process the form data upon form submission. This attribute essentially overrides the action attribute of the form element to which it belongs, allowing different submit buttons in the same form to send the data to different URLs.

This feature is particularly useful when you have a single form that needs to perform different actions depending on which submit button is clicked by the user. For instance, one button could be used to save the current state of the form, while another could submit the form for processing. By providing a formaction attribute to each button, you can direct the form data to different endpoints without needing to create multiple forms or use JavaScript for redirection.

The formaction attribute should contain a valid URL, which can be an absolute or relative path, and works with the GET and POST methods defined by the form's method attribute. It is supported in all major browsers, offering a simple way to control the flow of data for complex forms in a web application.

Syntax

<tagname type="submit | image" formaction="URL" >

Values

  • URLA page or resource to which form data will be sent.

Applies To

The formaction attribute can be used on the following html elements.

Example

<form action="formscript.php">
<input type="text" name="name" placeholder="Enter your name">
<input type="submit" value="Submit to Products">
<input type="submit" value="Submit to Contact Us" formaction="formcontact.php">
</form>

Browser Support

The following table will show you the current browser support for the HTML formaction Attribute.

Desktop
Edge Chrome Firefox Opera Safari
YesYesYesYesYes
Tablets / Mobile
Chrome Firefox Opera Safari Samsung Webview
YesYesYesYesYesYes

Last updated by CSSPortal on: 29th March 2024