Forums

Contact Form 7
get value for on_sent_ok using jQuery (for paypal integration) (4 posts)

  1. mxg
    Member
    Posted 3 months ago #

    CF7 v. 3.0.2.1

    i'm almost done in creating a custom PayPal call by using the on_sent_ok hook in the Additional Information.
    i'm also using the CF7 Dynamic Text Extension to grab user details.

    all values are ok (i've tested the form by redirecting to a page where i output all the posted data) but there's no way to get at the "select" or "radio" selected value with jQuery()

    this is the url so far:
    on_sent_ok: "location = 'https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_xclick&business=XXXXXX&currency_code=EUR&amount='+jQuery('#amount').children('option').is('selected').val()+'&return=XXXXXX&rm=2&cancel_return=XXXXXX&item_name=XXXXXX&email='+jQuery('#usr_email').val()+'&first_name='+jQuery('#usr_firstname').val()+'&last_name='+jQuery('#usr_lastname').val()+'&login_name='+jQuery('#usr_loginname').val()+'&number='+jQuery('input:radio[name=number]:checked').val()+'';"

    the option "amount" refers to a "select" cf7 tag (dropdown menu) with id=amount - it's needed by PayPal, it's the total amount of the transaction.
    the other option "number" refers to a "radio" cf7 tag with default:1, and it's a value that i need passing.

    both always output to "undefined", no matter what combination of jQuery syntax i use.

    anyone with an idea? Takayuki?

    http://wordpress.org/extend/plugins/contact-form-7/

  2. mxg
    Member
    Posted 3 months ago #

    gah! found it! well, actually found Taka's note on another post:
    http://wordpress.org/support/topic/plugin-contact-form-7-conditional-redirect?replies=15#post-1683148
    Takayuki, i'dd suggest you add your note to your FAQ or on a "Other Notes" tab on your plugin page on WordPress, 'cos it's not that trivial ;)

  3. mxg
    Member
    Posted 3 months ago #

    for anyone needing this, to get "select" or "radio" values from a submitted form in order, for instance, to populate a PayPal link, remember that CF7 first clears and resets the form, then runs the on_sent_ok hook: by then your "select" or "radio" has been resetted.

    to avoid this, in script.js change

    if (1 == data.mailSent) {
        $(data.into).find('form').resetForm().clearForm();
        ro.addClass('wpcf7-mail-sent-ok');
    
        if (data.onSentOk)
            $.each(data.onSentOk, function(i, n) { eval(n) });
    } else {

    in

    if (1 == data.mailSent) {
        if (data.onSentOk)
            $.each(data.onSentOk, function(i, n) { eval(n) });
    
        $(data.into).find('form').resetForm().clearForm();
        ro.addClass('wpcf7-mail-sent-ok');
    } else {

    the final stuff i put in the Additional Information box now is:
    on_sent_ok: "location = 'https://www.sandbox.paypal.com/?cmd=_xclick&business=XXXXXXX&currency_code=EUR&amount='+jQuery('#nmr').val()*50+'&return=XXXXXX&rm=2&cancel_return=XXXXXX&item_name=XXXXXX&tour='+jQuery('#tour').val()+'&email='+jQuery('#usr_email').val()+'&first_name='+jQuery('#usr_firstname').val()+'&last_name='+jQuery('#usr_lastname').val()+'&login_name='+jQuery('#usr_loginname').val()+'';"

  4. mxg
    Member
    Posted 3 months ago #

    ahem... almost solved...

    Google Chrome doesn't like that
    &amount='+jQuery('#nmr').val()*50+'
    in the url, so in the end i had to change the logic of payement process:
    first collect data, then send to page with php to check if value is null, from this page send (via button) to php script that compose safely the url and redirects via php-header to PayPal...

    tsk...

Reply

You must log in to post.

About this Plugin

About this Topic