简体   繁体   中英

Wordpress Contact Form 7 Radio-Button Conditional Redirect

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?

Hello how are you doing so I was looking for same thing and with help of your code i found solution

on_sent_ok:" 
  var utah = $("input[name=utah]:checked").val();
  var addiction = $("input[name=addiction]:checked").val();
  var discharged = $("input[name=discharged]:checked").val();
  if (utah == 'Yes' && addiction == 'Yes' && discharged == 'Yes'){
    location = 'example.com/city2'; 
  } else {
    location = 'example.com/city4';
  }
"

I used this code for my solution and it works.. In this i created three radiobuttons so if all are selected to yes then city 2 page load otherwise another page

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