Ok, if you’re having problems directing to several thank you pages when users fill out your form, this is a good trick to do it. This method was used because we didn’t want to install any additional plugins, we had two different thank you pages, we were tracking if the leads were coming from bing or facebook so we needed two thank you pages.
Step 1. CREATE THE FORM
Create your Contact Form 7 and and add these under form: [hidden lead-source “facebook”]
This basically creates a hidden field with the name lead-source and has the the data of “facebook”. Save your form and that’s all for step 1.
Step 2. ADD THIS CODE TO YOUR PAGE FOOTER.
<!– FORM THANKS PAGE REDIRECTION –>
<script>
document.addEventListener( ‘wpcf7submit’, function( event ) {
var inputs = event.detail.inputs;
for ( var i = 0; i < inputs.length; i++ ) {
if ( ‘lead-source’ == inputs[i].name ) {
//alert( inputs[i].value );
lead = inputs[i].value;
if (lead == “bing”) {
location = ‘/bing-thank-you/’;
}
if (lead == “facebook”) {
location = ‘/thank-you/’;
}
break;
}
}
}, false );
</script>
<!– FORM THANKS PAGE REDIRECTION –>
That’s it. So basically if the hidden variable reads bing for our case, it redirects to the page “bing-thank-you” if the variable reads facebook then it redirets to “/thank-you/”. This is a pretty cool method since you can do a lot with it. The line “if ( ‘lead-source’ == inputs[i].name ) {“, lead-source is the name of the input field you want to know its value, in our case we created a hidden input field to store the variables of either “bing” or “facebook”.
Learn more about CONTACT FORM 7 HERE.