1

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.

3
  • 1
    Different buttons alone won't work. You'll need JavaScript. Commented Mar 8, 2012 at 19:36
  • Use the JS to build the page I want to link to, or use it to perform the submit? Commented Mar 8, 2012 at 19:46
  • You'll need it to handle the different button submit actions. Commented Mar 8, 2012 at 19:46

2 Answers 2

6

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>
Sign up to request clarification or add additional context in comments.

Comments

-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>

1 Comment

as far as I know forms cannot be part of <table>, <tr> or <td>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.