Hybrid
Hybrid

Reputation: 21

Link to a page with submit button without form action/forms within forms

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.

Upvotes: 1

Views: 13261

Answers (2)

jakub_jo
jakub_jo

Reputation: 1634

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>

Upvotes: 6

Tom
Tom

Reputation: 1

Put a separate form within each <td>:

<table>
<tr><td><form action="action1.php"><input type="submit" name="button"></form></td>
    <td><form action="action2.php"><input type="submit" name="button2"></form></td>
</table>

Upvotes: -1

Related Questions