Redirecting without a condition
When you use the WordPress plugin “Contact Form 7” you can redirect the user to another page after submitting the answers by the follwing code:
on_sent_ok: "location.replace('http://www.redirectedpage.com');"
The line of code you have to copy into the “settings” box at the end of a specific form you created.
Redirecting on a condition
If you want to make the redirecting depending on a specific answer, you can use the following code:
on_sent_ok: " if (document.getElementById('car').value=='yes') {location.replace('http://www.redirectedpage1.com')}
else { location.replace('http://www.redirectedpage2.com/') } "
The code in bold letters has to be changed by your settings.
For example: The question with the id “car” has two possible answers: “Yes” or “No”. If a person selects “Yes” he or she should be redirected to “http://www.redirectedpage1.com”. If “No” is selected, the user should be redirected to “http://www.redirectedpage2.com/”.
4 Kommentare
Hi, thanks for the code. Tried the code, but I’m still having a problem with the conditional redirect; both options linked to the 2nd URL.
Radio Button choices: Paypal, Bank Transfer
I put this code in the additional settings, but it always leads to Google page instead of Paypal.
on_sent_ok: “ if (document.getElementById(‚paymentmode‘).value==’Paypal‘) {location.replace(‚http://www.paypal.com‘)} else { location.replace(‚http://www.google.com‘) } “
Any fix? 🙂
The conditional redirect code doesn’t work with Contact Form 7 version 3.4.1 . Keep getting „document.getElementById(…) is null“ error.
sada
aaaa