views:

27

answers:

1

So I have a retreat registration form that is hooked up to PayPal. Now, before I hooked it up to PayPal, I setup code in PHP to go through and check if each field was valid and sanitize them properly. After that, it would add this person to a database.

Now, what I wanted to happen after that is for it to redirect the user to the PayPal paying page, sending along all the POST information as well. Problem is I have no clue how to do that.

So far, my boundary is the form's action. If I want all the fields to be validated/sanitized and have the user put into my database, I set the form's action to the local register.php. If I want my user to actually be sent to PayPal where his information gets carried along aswell via POST then I set the form's action to https://www.sandbox.paypal.com/cgi-bin/webscr (Still in the PayPal sandbox.)

Is there a way that I can have the form's action set to register.php and then send the POST information to https://www.sandbox.paypal.com/cgi-bin/webscr?

+2  A: 

On the page you save your information, show a "please wait ... " message, then create a hidden form with action pointed to paypal url , via php put in all the fields in it , make them hidden and using javascript post the form automatically to paypal.

Sabeen Malik
Is there a way to do it without Javascript? I wanna make sure that people who've disabled it can still use this. Is there like a PHP way to submit a form?
NessDan
if people have disabled javascript, check for that BEFORE they reach this page and clearly alert them that for the payment to work they must enable javascript. As for PHP doing the post , it certainly can however you need to keep in mind that PHP is running on the server end and any post action it does will be between your server and paypal, thus the user will not be able to see the Paypal page where they actually complete the payment. I am not sure but check if you can send form data to paypal via GET instead of POST, if that is a possibility, then you can build the url and redirect to Paypal
Sabeen Malik
Thanks, I'm actually reading online about cURL that might be another solution.
NessDan
@NessDan: if you don't *need* to redirect your user to PayPal, using cURL to do a POST request is a viable solution (I recommended it but deleted my answer in case you needed a hard redirect)
BoltClock
CURL is not your solution, that i can assure you. The problem is, the user needs to reach the paypal site and based on the form data posted, they will be presented with the payment form, then the user needs to probably login and continue with completing the payment. Now when you use CURL, the data is being sent by the server, paypal will return the login page to your server, now what will you do with response from paypal? If you think about it a bit more,you would start to see the implications.
Sabeen Malik
@BoltClock .. if i understand this correctly, he is not talking about the IPN at this point, where CURL would completely make sense. The user needs to go to the PP site, login and continue to complete the payment, so this transmission/communication has to be between PP and the users browser directly.
Sabeen Malik
@Sabeen Malik: excellent point. Guess your JavaScript redirect solution would work then. +1
BoltClock
@NessDan .. when you come to think of it, why cant you just show a "continue to paypal" button and have them click on it to proceed to making the payment? So this will remove the need of javascript altogether.
Sabeen Malik
Ya you're right but now there's a new problem. The form takes you to a page called processing.php and it checks for errors, but an error could be that the field wasn't filled out at all. The registration form is gone already though, so what would I do from this step?
NessDan
Oh, and the reason why it just doesn't go straight to PayPal is because it has to add them to a database with all their info (plus an extra field for whether they paid or not.) Then, once the payment is complete, using IPN I find the user and change the paid field to true.
NessDan
OK, so instead of posting the form on processing.php, post the form to form page itself. On top of that page, validate the data, add into db and once you are ok with it, forward to the "please wait.." page. So now you can display errors on the form page, validate, redirect to the middle page and send them to PP.
Sabeen Malik
Even better, going off your idea, post to the register.php, validate, and if there's errors show them on the side, if no errors, show a success message and right underneath it there will be a "Finalize at PayPal" button to redirect. Thanks for the help! This thread is full of answer and win :D
NessDan
i am glad you sorted it out :)
Sabeen Malik