Currently seeking new career opportunities in web development, particularly with Laravel, Hire Me

HTML 5 Submit form - multiple actions with formaction

David Carr

Tutorials HTML

When working with forms there are often times it would be really handy to be able to submit the form and depending on the button clicked changed the form action the data is posted to. Normally this has not been possible so we find workarounds.

I recently found the need for this again and come across a HTML attribute called formaction which is amazing for this! This attribute allows you to specify the url to post to which when pressed will override the form action attribute.

For instance take this form, by default when the form is submitted the form will be posted to next.html but if the input with formaction=”alt.html” is pressed then the form is posted to alt.html instead.

<form action="next.html" method="post">

 <p><input type="submit" name="altSubmit" formaction="alt.html" value="Go to Alt"></p>
 <p><input type="submit" name="nextSubmit" value="Go to Next"></p>

It’s worth pointing out this only works on IE 10 and above and the latest Chrome, Firefox etc

Laravel Modules Your Logo Your Logo Your Logo

Become a sponsor

Help support the blog so that I can continue creating new content!

Sponsor

My Latest Book

Modular Laravel Book - Laravel: The Modular way

Learn how to build modular applications with Laravel Find out more

Subscribe to my newsletter

Subscribe and get my books and product announcements.

Learn Laravel with Laracasts

Faster Laravel Hosting

© 2006 - 2024 DC Blog. All code MIT license. All rights reserved.