dongping4901 2016-06-17 15:53
浏览 252
已采纳

HTML表单完成两个动作? 验证然后通过一个提交按钮重定向

I'm having trouble integrating the paypal form into my order page.

My order page currently already has a form that the user fills out, and a submit button:

<form id="order-form" form name="orderform" method="post" action="send_order_email.php">

This send_order_email.php goes through and validates whether the form is valid or not, if not it redirects to a sorry page if valid I would like it to redirect to paypal with the below:

 <form target=paypal action="https://www.paypal.com/cgi-bin/webscr" method=post>
    <input type=image src="https://www.paypal.com/en_GB/i/btn/x-click-but22.gif " border=0 name=submit alt="Make payments with PayPal - it's fast, free and secure!">
    <input type=hidden name=add value=1>
    <input type=hidden name=cmd value=_cart>
    <input type=hidden name=business value=" info@info.co.uk">
    <input type=hidden name=item_name value="item">
</form>       

At the moment I can only get either the form to send by making the action="send_order_email.php" or I can make the form redirect to paypal by making the form target=paypal action="https://www.paypal.com/cgi-bin/webscr", this however doesn't go through any of the validation and sends no emails.

How can I get the form to do both actions - Verify one form and then redirect using paypals submit form all through one submit button?

Any help would be really appreciated.

Thanks!

  • 写回答

2条回答 默认 最新

  • dongqiao6445 2016-06-17 16:03
    关注

    After send_order_email has verified it's correct, just generate a html page with the form you posted (the one with hidden fields), populate it with the data you've received and autosubmit it using javascript, i.e.

    <body onload="document.theform.submit()">
       <form target=paypal action="https://www.paypal.com/cgi-bin/webscr" method=post name="theform">
        <input type=image src="https://www.paypal.com/en_GB/i/btn/x-click-but22.gif " border=0 name=submit alt="Make payments with PayPal - it's fast, free and secure!">
        <input type=hidden name=add value=1>
        <input type=hidden name=cmd value=_cart>
        <input type=hidden name=business value=" info@info.co.uk">
        <input type=hidden name=item_name value="item">
    </form>   
    </body>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 微信会员卡等级和折扣规则
  • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分