0

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>
Community
  • 1
  • 1

1 Answers1

0

Not sure why you want to do this way, if you want to send email to buyer with all the necessary information upon payment confirmation, I would suggest you to use IPN(Instant Payment Notification).

Vimalnath
  • 6,373
  • 2
  • 26
  • 47
  • The email is for me, and its purpose is to get information from the customers who don't go through the entire paypal process. In the case the customer closes the paypal window, I won't be able to get any information he posted on my website because IPN is only usefull when the customers actually finishes he payment process. That's why I need to make 2 submissions with one click. – Jean-Baptiste Queromes Nov 25 '14 at 10:06
  • this case, you might first need to send email and then initiate the paypal transaction.I would just use Jquery ajax to call a php file send email, then upon email sent, call the paypal https://www.paypal.com/cgi-bin/webscr.Becasue this function $.ajax({url: "https://www.paypal.com/cgi-bin/webscr", data: ("form").serialize(), type : "POST", success: function(){ will not return `success` – Vimalnath Nov 25 '14 at 10:48
  • Thanks for the answer. So am I correct if I translate what you've said in this js code (it would be just an inversion of the two ajax post functions) : ? ' $(document).ready(function doublesubmit() { $.ajax({url: "reserve.php", data: $("form").serialize(), type : "POST", success: function(){ $.ajax({url: "https://www.paypal.com/cgi-bin/webscr", data: $("form").serialize(), type : "POST", } }); }; return false; };' – Jean-Baptiste Queromes Nov 25 '14 at 11:30