rustyeddy
2/2/2015 - 7:24 PM

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 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);			
	}
}