一次点击提交2个表单 - 一个表单依赖于另一个表单的结果

时间:2014-05-09 14:25:46

标签: php jquery forms form-submit

情况如下 - 在我的订单页面上,我有2个表单:“订单提交”和“支付PayPal按钮”。客户必须提交2个表格(一个接一个) - 我想把它带回一个提交。

设定:

表单1:调用在提交时发送给Commerce的submit.php脚本(计算+订单数组)。

表格2:致电Paypal脚本以支付总额。

现在的工作方式:客户提交表格2(Paypal),Ipn.php在接受付款后获得“已完成”通知,并使用付款信息更新DBase。 然后,客户必须提交表格1,更新来自Dbase的付款信息(金额为付款= 0)。 Commerce通过更新的付款信息获取订单。

我希望客户只提交表格2(Paypal),其余的则自动完成。

A)来自Dbse的表格1更新

B)表格1在更新后自动提交。

我的php文件。

1)submit.php(我控制了它)

2)Paypal(我无法控制)

3)Ipn.php(我控制它)

表格1:

  <form action="../../order/submit.php" id="Formulaire" method="post" name="Formulaire" target="preview">

  <button id="submit" class="buttonsubmit" name="_Commande" onclick="return checkform();" type="submit">
         Order / Commandez </button>

表格2:

 <form action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post" name="Paypal" target="_blank" id="Paypal">

 <button class="buttonsubmitpaypal" id="buttonpaypal" name="_Paypal" onclick="alert('IMPORTANT: you MUST come back WITHOUT refreshing browser, click PREVIEW to reflect payment then SUBMIT your order.');PayPalSubMitFinal();" />

我看到了一篇可能为我提供解决方案的文章,虽然(因为我不是程序员 - 但我可以适应),我不确定这对我来说是不是正确的解决方案,我真的不明白如何实现:

Submit forms, one after another with jQuery?

我正在考虑的解决方案,不确定它是否切合实际:

将Ipn.php集成到我的Submit.php脚本中,当Paypal发送“已完成”通知时,它会触发提交机制。不知道如何实现“听取if的部分”。但是,脚本将无法从订单表单1获取信息......所以......

感谢您的提示。

更新 - 下面建议的测试解决方案:

我在我的submit.php表单中集成了ipn.php,并在收到“已完成”通知后,我补充道:

  $emailto = 'me@me.ca';      // this is to ckeck if it works - I receive it.
  $subject = $_POST['payment_status'];
  $text ="success submit IPN". $_POST['custom'];
  $headers = 'From: "" <"' . $_POST['payment_status']. '">'. "\r\n".
  "Content-type:text/html;charset=iso-8859-1" . "\r\n";
  mail($emailto, $subject, $text, $headers);

//然后我触发提供的脚本(我在其他地方测试了它,它可以工作)

  $click = '<script type="text/javascript">window.top.parent.parent.submitsubmit();</script>';
  echo $click;

脚本本身:

 function submitsubmit() {
 $("#submit").click();
 }

结果:未触发提交按钮。我看不出有什么问题。

我在这里的一个新问题中简化了我的问题:

Can we trigger a script on original window even if script runs in _blank window

1 个答案:

答案 0 :(得分:0)

Paypal发送完成通知后,您可以使用jQuery检测并发送第二个表单。你需要包含jQuery jQuery包括(HTML / PHP):

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>

检查并提交代码:

if(completed) {        // Assuming completed is a variable representing the
// state of the completed notice
    $("#submit").click();
    // "submit" is the ID of the second form's submit button.
    // This statement selects this button and clicks it, which fires the
    // form's action attribute as it would if the user clicked Submit.
}
else {
    throw new Error("Paypal form not submitted");
    location.href = "paypalform.html";
}

希望这会有所帮助 -CE