Skip to content

Instantly share code, notes, and snippets.

@rustyeddy
Created February 2, 2015 19:24
Show Gist options
  • Save rustyeddy/ac6442e98e37c5c6c893 to your computer and use it in GitHub Desktop.
Save rustyeddy/ac6442e98e37c5c6c893 to your computer and use it in GitHub Desktop.
Contact Form 7 - Redirect to a different thank you page based on input from from a pull down select form field.
/**
* Contact form 7 - Redirect to a specific page based on the value of a form
* field. In this specific example I created a drop down menu item and gave
* it an id of 'select-menu', I also created .
*/
function cf7_redirect() {
// Set the base url for contact-form-7
var url = document.referrer;
// I used the HTML ID 'select-menu' for this example
var page = document.getElementById('select-menu').value;
/**
* The options for the select are "Page 1", "Page 2" & "Page 3".
* The urls are the permalinks not including the base url 'page-1', etc.
*/
switch (page) {
case "Page 1":
url = url + 'page-1';
break;
case "Page 2":
url = url + 'page-2';
break;
case "Page 3":
url = url + 'page-3';
break;
default:
url = null;
}
// Now redirect if everything went well
if ( url !== null ) {
location.replace(url);
} else {
alert("Error with selection: " + page);
}
}
@You4eea
Copy link

You4eea commented Jun 4, 2018

This is exactly what I am looking for... So how would I use this? would I put in my child-theme functions file? or a customer page where the cf7 shortcode is located? Please advise.

@vitorliduario
Copy link

And do we insert the code in function, in additional configurations of form7 or in snippets?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment