tags:

views:

26

answers:

2

I am setting up a paid subscription service and want to keep the signup form to one page. I use PayPal as my payment processor and the standard way of dealing with paypal is to create "Buttons" that POST to PayPal.

However, I need to process the form data before I send the user to paypal. Once I have processed the data, how would I redirect the user to paypal from the server?

Thanks

A: 

Assuming you have the exact URL on paypal to which you will send them, stored in the variable $url, adding this line after the processing should do the trick:

header("Location: ".$url);

For more info on the header function, check out the description in the php manual: http://php.net/manual/en/function.header.php

JGB146
Thanks, but with that how will paypal know the subscription settings? PayPal does not accept GET requests.
Matthew V
Sorry, I overlooked that the Paypal buttons were actually posting as part of a form. I feel a bit silly about that, since I use Paypal on my site to do the same thing. The way I do things there is to have Paypal send the users to my form to finalize their processing after they have paid. Not quite as elegant as collecting the info before you send them to Paypal, but it gets the job done.
JGB146
A: 

Since you must use POST, the best method may be to add a bit of javascript to auto-submit the form to a page that you send users to on your site after they complete the rest of the registration process. Make sure you include checks to ensure that the rest of the registration was valid before you show the code. So it would be something like this:

<?php
if (checkRegistration()) {
 ?> 
 <html><head><title>Registration Checkpoint</title>
  <script type="text/javascript">
    window.onload = function () {
        var form = document.getElementById("PDFGenerationForm");
        form.submit();
    };

    function OnFormSubmit() {
        alert("Submitting form.");
    }
  </script>
 </head><body></body></html>
 <? 
}
?>
JGB146
Thanks, I've done what you have recommended and it works like a charm.
Matthew V
Glad to hear it. You can mark this as the accepted answer by clicking the check mark.
JGB146