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!

我在将paypal表单集成到订单页面时遇到问题。 p>

我的订单页面目前已经有一个用户填写的表单和一个提交按钮: p>

 &lt; form id =“order-form”form name =“orderform”  method =“post”action =“send_order_email.php”&gt; 
  code>  pre> 
 
 

此send_order_email.php会通过并验证表单是否有效,如果不是 重定向到一个抱歉的页面,如果有效,我希望它重定向到paypal与下面: p>

 &lt; form target = paypal action =“https://www.paypal。  com / cgi-bin / webscr“method = post&gt; 
&lt; input type = image src =”https://www.paypal.com/en_GB/i/btn/x-click-but22.gif“border = 0  name = submit alt =“使用PayPal付款 - 快速,免费且安全!”&gt; 
&lt;输入类型=隐藏名称=添加值= 1&gt; 
&lt;输入类型=隐藏名称= cmd值= _cart&gt  ; 
&lt;输入类型=隐藏名称=商业价值=“info@info.co.uk”&gt; 
&lt;输入t  ype =隐藏名称= item_name value =“item”&gt; 
&lt; / form&gt;  
  code>  pre> 
 
 

目前,我只能通过 action =“send_order_email.php” code>获取要发送的表单,或者我可以制作 通过制作 form target = paypal action =“https://www.paypal.com/cgi-bin/webscr” code>将表单重定向到payPal,但是这不会通过任何验证 并且不发送任何电子邮件。 p>

如何让表单执行这两个操作 - 验证一个表单,然后使用paypals提交表单通过一个提交按钮重定向? p> \ n

非常感谢任何帮助。 p>

谢谢! p> div>

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>

If you use POST, or rather, if PayPal requires POST, then I don't think you can redirect. Not in the sense of returning a Location: http://www.paypal.com/foo/bar HTTP header, anyway.

You can have send_order_email.php take the information provided by the user, and submit it to PayPal. That is, your PHP code can construct an HTTP POST request with the various fields, then send it off to www.paypal.com and process the result. But I doubt that'll work, because PayPayl will probably ask for a credit card number or PIN that you shouldn't have.

As BoydP said above, if you can do validation on the client in JavaScript, great. But if you want to (or need to) do validation on the server, in PHP, then the best approach might be to use two screens: in the first, the user fills in information. In the second, the page displays the information and asks the user to confirm the transaction, using the <form> code you pasted above.