• I’ve seen a few questions similar to this on here, but no working answers, etc.

    I have a Contact 7 form with a radio button with four options, which of 4 states you reside in. I need for when the form is submitted for it to redirect to that states page.

    I have tried a number of different options, and a few have kind of worked… like this is what I currently have in the ‘Additional Settings’ area in Contact Form 7…

    on_sent_ok: “var Iso = $(“input[name=your-city]:checked”).val() ; if(Iso == ‘1’ ){ location = ‘example.com/city2’; } else if (Iso == ‘2’ ){ location = ‘example.com/city2’; } else if (Iso == ‘3’ ){ location = ‘example.com/city3’; } else { location = ‘example.com/city4’; }”

    Obviously the URL’s are full url’s in my code… Problem is it’s always going to /city4 no matter what is selected. I’ve heard this is because by the time it’s sent it’s not sending back the correct info, but how would I go about making this work then?

    https://www.ads-software.com/plugins/contact-form-7/

Viewing 2 replies - 1 through 2 (of 2 total)
  • zaus

    (@zaus)

    CF7 resets the form values as soon as a “success” response comes back from the CF7 ajax, and then it performs the on_sent_ok callback.
    You can see this in lines 90 and 134 of the cf7 scripts.js file.

    I’d consider this a bug, although maybe the dev thought it was ‘more secure’ to not easily allow JS access to form values; the only thing I can think to address it (other than modifying CF7 code) is asking the developer to “fix” it. Disabling AJAX in CF7 (e.g. via this plugin https://www.ads-software.com/plugins/contact-form-7-extras/ and there’s also a define way to do it that I forget) might work, but more likely it will prevent the javascript callback from firing.

    Actually I’m wrong, I was looking at the wrong lines (it should be resetting on line 156 after performing the callback).

    • This reply was modified 8 years ago by zaus. Reason: I was wrong
    • This reply was modified 8 years ago by zaus.
    zaus

    (@zaus)

    I suspect you’re comparing the wrong values. Add console.log('radio-input', lso); to your callback, then open developer tools (<kbd>F12</kbd>, or right-click the page and choose ‘Inspect’) and go to the “Console” tab to see what it prints. If lso is actually a number (1 vs '1') update your comparison accordingly.

    • This reply was modified 8 years ago by zaus.
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘WordPress Contact Form 7 Radio-Button Conditional Redirect’ is closed to new replies.