2

I have two forms on my webpage - one that writes certain information to a database, and one that lets you pay using Paypal (the page I have is for buying a product).

Right now, there are the two forms, but I want to make it so that both submit at the same time. That is, when you click the Paypal button, it posts both forms.

Can I put them both in the same post method somehow? Or how can I solve this problem?

I want it so a customer can buy something, and the Paypal post executes (for the actual payment) but the page also writes to my own database with the information of the customer.

I'm fine with using jQuery and/or any libraries.

Here's my JS: http://slexy.org/view/s2u2Jsr2RI

Here's my HTML: http://slexy.org/view/s2NgzHRES4

Here's my post.php: http://slexy.org/view/s208WfbKso

AKor
  • 8,550
  • 27
  • 82
  • 136

3 Answers3

1

You could submit your original form using AJAX, and then in its success callback, submit your paypal form.

alex
  • 479,566
  • 201
  • 878
  • 984
  • @Andrei Korchagin Check [Summer's answer](http://stackoverflow.com/questions/4823961/writing-to-my-db-and-submitting-a-form-to-paypal-using-the-same-form/4824012#4824012). – alex Jan 28 '11 at 01:47
1

You're already using jQuery to submit the PayPal form:

$('#paypalButton').click(function(){

  $.post('post.php', $('#myForm').serialize(), function(){

     $('#paypal').submit();
  });

});

Just have it post the other form right afterward, after clicking on the #paypalButton!

$('#paypalButton').click(function(){

  $.post('post.php', $('#myForm').serialize(), function(){

     $('#paypal').submit();
  });

  $.post('mydbprocessingurl.php', $('#myOtherForm').serialize());

});

Summer
  • 2,488
  • 3
  • 23
  • 32
  • I'm a bit confused. The paypal form's action="https://www.paypal.com/cgi-bin/webscr", and my form's action="post.php". The paypal form is #paypal and my db form is #myForm. I just don't know where exactly to put the names. – AKor Jan 28 '11 at 01:52
  • Hi - actually, I think your original code should work. Initially you post the data to post.php from #myForm, then after that's done, in the callback, you submit the form with id #paypal. What's not working? – Summer Jan 28 '11 at 02:20
0

Post back using the first form. Return to another page with "Redirecting...." where the paypal form controls are. Use javascript to post that form on page load.

or

Have the first form perform an ajax request. On postback, execute javascript which posts the second form.

Valamas
  • 24,169
  • 25
  • 107
  • 177