Link to a page with submit button without form action/forms within forms
I know this is way to late, and OP has, hopefully, figured out a solution back in 2012. But in case someone finds this through search, here's a possible solution:
Use the formaction attribute of the button element:
<form action="/actions/1" method="post">
<button type="submit">Submit to default action</button>
<button formaction="/actions/2" type="submit">Submit to action 2</button>
</form>
Hybrid
Updated on June 04, 2022Comments
-
Hybrid almost 2 years
I am working on a php/html/js page.
I have two buttons. They both need to submit the same form data, but I want one to link to another page(which needs the form data from this page) and one to do something on the current page.
I don't know how to make the linkage button go to another page AND post the same form data AND not lose the post data (using something like header('Location:')).
I can't set form action="page.php" because then both buttons would change pages. A form within a form doesn't work either.
My setup is as follows:
<form method="post" action="" name="aform"> <table> <tr><td><input type="submit" name="button" value"Clickit"></td> <td><input type="submit" name="button2" value"Click to link"></td> </table> </form>
Help appreciated.
-
j08691 about 12 yearsDifferent buttons alone won't work. You'll need JavaScript.
-
Hybrid about 12 yearsUse the JS to build the page I want to link to, or use it to perform the submit?
-
j08691 about 12 yearsYou'll need it to handle the different button submit actions.
-
-
Ilya Kushlianski about 6 yearsas far as I know forms cannot be part of <table>, <tr> or <td>