简体   繁体   English

相同的表单数据,两个单独的提交按钮上的不同操作

[英]same form data, different actions on two separate submit buttons

I have what is essentially a shopping cart that needs to have two separate checkout options. 我有一个基本上是购物车,需要有两个单独的结账选项。 The first of which takes the user away from the site, but form data must be posted. 第一个使用户远离站点,但必须发布表单数据。

How can I create two submit buttons that will send the same form data to their own separate page? 如何创建两个提交按钮,将相同的表单数据发送到他们自己的单独页面?

If I understand correctly, you have 2 submit buttons on the same page and both of them have the same form if that is so, this should do the trick. 如果我理解正确,你在同一页面上有2个提交按钮,如果是这样的话,它们都有相同的形式,这应该可以解决问题。

if(isset($_POST['name1'])) {
//do stuff
}

if(isset($_POST['name2'])) {
//do other stuff
}

Well you could do this: - 那么你可以这样做: -

define your form with action="" 用action =“”定义你的表单

then have two buttons: - 然后有两个按钮: -

<input type="button" value="button1" onClick="this.form.action='your_first_action_url'; this.form.submit()">
<input type="button" value="button2" onClick="this.form.action='your_second_action_url';this.form.submit()">

you could set an onclick handler to the buttons and change the form action dinamically. 您可以为按钮设置onclick处理程序并以动态方式更改表单操作。
I'm giving this answer because you have the javascript tag and i assume the external site receives the parameters via POST METHOD so you could not make a redirection in php 我给出了这个答案,因为你有javascript标签,我假设外部网站通过POST METHOD接收参数,所以你不能在PHP中进行重定向

But i wouldn't trust in this because it require the users having javascript enabled... 但我不相信这一点,因为它要求用户启用javascript ...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM