Reputation: 8882
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
Upvotes: 2
Views: 1049
Reputation: 2498
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());
});
Upvotes: 1
Reputation: 490183
You could submit your original form using AJAX, and then in its success callback, submit your paypal form.
Upvotes: 1
Reputation: 24729
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.
Upvotes: 0