kylex
kylex

Reputation: 14426

How can I submit a form to two different pages (not at same time)?

I need to submit a page to two pages depending on which button is triggering the submit. Both pages needs to be able to pick up the $_POST data being sent. This is what I have so far, but it's not working.

<form name="user" action="" method="POST">
  <textarea name="tname" id="tname"></textarea>
  <input type='button' value='Submit'
    onclick="document.user.action='edit.php'; document.user.submit(); this.form.target='_self'; return true;">
  <input type='button' value='Preview'
    onclick="document.user.action='preview.php'; document.user.submit(); this.form.target='_blank'; return true;">
</form>

Both pages are opening in the same window (preview button should be opening in a new window).

Upvotes: 4

Views: 1624

Answers (1)

Annie
Annie

Reputation: 6631

Setting the target the same way you set the action, and setting it before you submit the form works for me:

<form name="user" action="" method="POST">
<textarea name="tname" id="tname"></textarea>
<input type='button' value='Submit'
       onclick="document.user.action='edit.php'; document.user.target='_self'; document.user.submit(); return true;">
<input type='button' value='Preview'
       onclick="document.user.action='preview.php'; document.user.target='_blank'; document.user.submit(); return true;">
</form>

Upvotes: 5

Related Questions