如何将表单提交到两个不同的页面(不是同时)?

时间:2022-11-24 08:45:15

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.

我需要将页面提交到两个页面,具体取决于触发提交的按钮。两个页面都需要能够获取正在发送的$ _POST数据。这是我到目前为止所做的,但它不起作用。

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

两个页面都在同一个窗口中打开(预览按钮应该在新窗口中打开)。

1 个解决方案

#1


5  

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>

#1


5  

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>