开发者

PHP POST to URL with user being redirected

So I'm making a check out cart on my website. I'm using PayPal as the payment system but before I transfer the customers to PayPal I get their details. To do that I POST from index.php to index.php, run my code to retrieve the POSTed info and store it in a database and now wish to redirect the customer to PayPal.

Unfortunately you have to POST all the cart data to PayPal:

<form actio开发者_运维百科n="https://www.paypal.com/cgi-bin/webscr" method="post">

The only way I see around this is to post to index.php, collect the user data, then have a button show up saying click here to pay via PayPal. That's one extra step that I want to avoid.

Any way to POST to index.php, collect the data, then post the PayPal info to the PayPal website? Or any other ideas?

Thanks


you would need 2 forms on your page, one form that posts back to index.php and a second form that posts to paypal

after the first form posts back to index.php, echo javascript in the body tag to submit the paypal form when it loads

    <?php
   if(isset($_POST['mydatafield'])){

        do database stuff

        $LOAD = 'document.paypal.submit();';
    }
    ?>
    <body onload="<?php echo $LOAD ?>">
    <form name="paypal" action="paypal.com?yadayada">
    paypal fields
    </form>
    <form name="myform" action="index.php">
    your form stuff
    submit button
    </form>


You may fire submitting programmatically with JavaScript, eg:

<form action="https://www.paypal.com/cgi-bin/webscr" method="post" id="paypal_form">
...
<script type="text/javascript">
function submitPay(){
  document.getElementById("paypal_form").submit();
}
</script>


You do not need to re-post your form from the client in the sense mentioned in other answers. You can instead use cURL to POST the data to PayPal and make it all look transparent to the user. Kinda like a forwarding of the posted form. You act on the data (save it, manipulate it or whatever) and forward the post to Paypal all in a single user transaction.

Here's a simple example: http://davidwalsh.name/execute-http-post-php-curl

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜