1

I'm trying to submit two forms with a single click. I am trying to open a new window so the user can pay with paypal.

Here's how it works:

There is a form to book an appointment.

If the user selects to pay with paypal radio button, and the form is submitted then a new paypal checkout form will be added to the page outside of the original form. like so:

if ($paypal_radio.eq(1).attr('checked')) {

    //make paypal buttons
    $('#content').append('<div id="paypal_form_container">');
    var $paypal_form = $('#paypal_form_container');

    //make the form template
    var paypal_form_template ='\
    <form action="https://www.paypal.com/cgi-bin/webscr" target="_blank" method="post" id="paypal_form"> \
    <input type="hidden" name="cmd" value="_xclick"> \
    <input type="hidden" name="business" value="email@email.com"> \
    <input type="hidden" name="lc" value="US"> \
    <input type="hidden" name="item_name" value="whatever"> \
    <input type="hidden" name="currency_code" value="USD"> \
    <input type="hidden" name="lc" value="US"> \
    <input type="hidden" name="rm" value="1"> \
    <input type="hidden" name="Cleaning Service" value="whatever"> \
    <input type="hidden" name="amount" value="'+totalValue+'"> \
    </form> \
    ';

    //add the form to the page
    $paypal_form.html(paypal_form_template);

    //submit both forms
    $('#paypal_form').submit();
    $(this).parents("form").submit();
}

I want the paypal form to be submitted and open in a new window (notice the target blank), then for booking form to be submitted to the current page.

My issue is that only the last submit value is being sent, whichever it one is last, doesn't matter.

What is the best way to handle this and send boths forms with one click?

puddletown
  • 215
  • 1
  • 3
  • 5

0 Answers0