I am currently trying to integrate PayPal into our existing Web Application.
The Web Application is using ASP.NET WebForms.
Since in WebForms we have a form element around (almost) everything, I wonder how to integrate a PayPal Button which uses a form itself.
Is there any way to do it?
Yes. I do it in a three step process:
- Remove the form tag from the PayPal code since you can't have nested forms.
- Add an ID, class, or something to the PayPal button to let you find it in a jQuery function (this example uses an id of
paypalbutton
).
- Add a jQuery script to catch the click and override the form post:
This may need to be modified to work with your specific code (but it may work as is):
$(document).ready(function() {
$("#paypalbutton").on("click",function(n) {
n.preventDefault();
$("#aspnetForm").attr("action","https://www.paypal.com/cgi-bin/webscr");
$("#aspnetForm").submit(); //or whatever your WebForms form element is called
});
});