I'm quite familiar with HTML and PHP, but realy novice in jQuery and Ajax.
After searching quite a while, like here : One form, One submission button, but TWO actions and here : Writing to my DB and submitting a form to Paypal using the same form?, I'm still confused with the eaxact code I have to write into my HTML file.
What I want to do is with only one click on the "submit" button, sending an email with the data entered by the user (via the "reserve.php" file) and sending the user to the paypal payment page.
Sorry to ask again the same question, but every try I made combining the different solutions proposed here and elsewhere lend me to nothing.
Here is my simplified HTML code :
<html>
<head>
<title>Bienvenue Telecom</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<meta name="description" content="" />
<meta name="keywords" content="" />
<link rel="shortcut icon" type="image/x-icon" href="/images/favicon.ico" />
<!--[if lte IE 8]><script src="css/ie/html5shiv.js"></script><![endif]-->
<script src="js/jquery.min.js"></script>
<script src="js/jquery.scrolly.min.js"></script>
<script src="js/skel.min.js"></script>
<script src="js/init.js"></script>
<noscript>
<link rel="stylesheet" href="css/skel.css" />
<link rel="stylesheet" href="css/style.css" />
<link rel="stylesheet" href="css/style-desktop.css" />
</noscript>
<!-- Here is the function I tried to make myself to submit the same form both to paypal and to the reserve.php -->
<script>
$(document).ready(function doublesubmit() {
$.ajax({url: "https://www.paypal.com/cgi-bin/webscr", data: ("form").serialize(), type : "POST", success: function(){
$.ajax({url: "reserve.php", data: $("form").serialize(), type : "POST",
}
});
};
return false;
};
</script>
</head>
<!-- Here is the body of my page, with the only form the user has to fill in -->
<body>
<form id="form" target="_blank" method="post">
<input type="hidden" name="business" value="XXXXXXXX">
<!-- many other hidden and visible input values -->
<input type="submit" value="Send request" name="submit" border="0" src="https://www.paypalobjects.com/en_US/i/btn/btn_paynowCC_LG.gif" alt="PayPal - The safer, easier way to pay online" onclick="doublesubmit();">
</form>
</body>
</html>