views:

56

answers:

3

I have a form were a user enters information, and then I have a PayPal button that the user will click once the fields have been filled in. The problem I'm having is how to you capture the user information when the paypal button is clicked, if the form has action="http://paypl.com/something/something".

Do I have to make this a 2 page process - one for me to capture the user information and then one to have the user click the paypal button?

By the way - the PayPal button directs the user to paypal.com to actually make the payment.

+3  A: 

You have a few options here. You could make two forms, one which submits to your server where you capture the user information, and then display a second form with a "Pay Now" button. As a second option, you could extract the information from the form using JavaScript and submit it to your server using AJAX, then submit the form to PayPal when the AJAX request completes. This may or may not be more complicated, but it will not alter the existing user interface, which may be desirable.

Josh
I thought about ajax but i thought there had to be a better way. I'm going to try ClarkeyBoy's solution.
Catfish
His solution may very well work. I forget off the top of my head if PayPal requires a POST or not
Josh
+3  A: 

I would make the action the current page, catch the button click and store the user information, then use header: Location("http://paypl.com/something/something");. Its something like that anyway. Hope this helps.

Edit: Also see the other answer by Josh. They are equally good possibilities. Note that the Ajax option would require JavaScript to be switched on - so safeguards would have to be put in place in case it is switched off.

ClarkeyBoy
I can't believe i didn't think of this.
Catfish
Dont worry - everyone misses obvious things from time to time. It often takes multiple people to find the best solutions - hence sites like Facebook are developed by multiple people!
ClarkeyBoy
+3  A: 

Guys, there's an easier solution here. Paypal allows you to pass those values through to it, then it will spit them back to you. There's actually two methods of getting the data back--a return URL that posts upon completion with return values (I've not been terribly lucky making that work) then a separate function that sends you a post upon completion of a transaction to a separate page on your site, where you can collect back all the variables you posted to the site. I suggest the latter because on a buy it now page there's a possibility of the user not being returned to the site because the return button UI is pretty weak on PayPal's end.

To set it up you'd log in to your PayPal account, click on myaccount > profile > website payment preferences. Enabling the "payment data transfer" will do the trick. Once you've got it setup correctly, upon completion of a transaction it'll send to the page of your choice a post of everything you sent it....remember, you can send in variables such as Name, Address, etc just by defining them properly in the form. All the variables available are found here

Sure, you could go through grabbing the elements from the form via Jquery or the like, then do an onclick save to DB, but why fight it? It's a heck of a lot more work and may have issues if Javascript is off.

Don't forget to build a sandbox site to test! Good Luck.

bpeterson76
I thought there was something like that also, but to be honest I didn't bother re-reading the PayPal docs. Good answer.
Josh