简体   繁体   中英

How to add form field value to query parameter to Contact Form 7 on_sent_ok redirect URL?

I have tried several methods for this after searching online, including various SO answers.

Current I am trying this:

Form field code:

[dynamichidden form-session-id "form_session_id" id:fsid]

Code in Additional Settings:

on_sent_ok: 'location.replace("http://www.example.com/page-2/?fsid=" + jQuery("input[form-session-id=form_session_id]").val());'

After submitting my form I am redirected to:

http://www.example.com/page-2/?fsid=undefined

Can't get that fsid value in there! I admittedly don't know how to use this portion of the code:

input[form-session-id=form_session_id]

So that could be the issue...


I have also tried using this code in the Additional Settings field, as seen at https://wordpress.stackexchange.com/questions/19966/get-values-from-contact-form-7-wp-plugin :

function my_redirect() {
        var fsid = document.getElementById('fsid').value;
        var url = 'http://www.example.com/page-2/?fsid=' + fsid;
        window.location = url;
    }
on_sent_ok: 'my_redirect();'

In this case no redirect at all happens.

Does your page actually have this hidden field? On my page it wasn't rendered untill i remove id:fsid part from the shortcode: [dynamichidden form-session-id "form_session_id"]

In on-sent-ok change input[form-session-id=form_session_id] to input[name=form-session-id] :

on_sent_ok: 'location.replace("http://www.example.com/page-2/?fsid=" + jQuery("input[name=form-session-id]").val());'

I've been looking all over for a similar solution and this worked! Using Contact Form 7, I'm selling tickets on PayPal and I have a quantity field the called 'ticketnumber'.

In Additional Settings I have this:

on_sent_ok: 'location.replace(" https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=XXXXXXXXXL&quantity= " + jQuery("input[name=ticketnumber]").val());'

Works like a charm!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM