Contact Form 7 Issues Tricks and Solution

Contact Form 7 Multi Step Form: Solution of Redirecting Different Form Based On Selection

Contact Form 7 Multi Step Form Redirect to Different Form Based on Selection

This Post is for advanced users. So if you are using Contact Form 7 and Contact Form 7 Multi Steps Form and want your form to go to or Redirect Different Form based on Radio button or Drop down or Checkbox selection, then this post can help you.

I have used Jquery and Ajax to solve this issue. If you have any Question, Please ask question in the comments section.

<script>

jQuery(document).ready(function(){
 jQuery('input[type="radio"][name="radio-20"]').bind('click',function(){
	var ompp= jQuery(this).val();
	 console.log(ompp);
  
  jQuery.ajax({
		url:"<?php echo admin_url('admin-ajax.php');?>",
		type:"GET",
		contentType: "application/x-www-form-urlencoded;charset=UTF-8",
		 
		data:{
			
    		action: 'stravyfuncajax23',
	 		radiovalue:ompp
		     },
	  success: function(responsea){
		  jQuery("#bm").html(responsea);
console.log(responsea);
if(responsea=="Build Muscle"){
document.addEventListener( 'wpcf7mailsent', function( event ) {
    if ( event.detail.contactFormId === "1719") { location.replace("http://example.com/build-muscle-form-page/");}}, false );
}
else{
document.addEventListener( 'wpcf7mailsent', function( event ) {
    if ( event.detail.contactFormId === "1719") { location.replace("http://example.com/lose-weight-form-page/");}}, false );
}

}
	
});

 });		


});

</script>
in Function.php

add_action('wp_ajax_stravyfuncajax23','searchbyom');
add_action('wp_ajax_nopriv_stravyfuncajax23','searchbyom');
function searchbyom(){
$searchword1= $_GET['radiovalue'] ; 

if($searchword1=="Build Muscle"){

 echo "Build Muscle";
}else
{
echo "Lose Weight";
}
die();
}
The Contact Form 7 Code i used

First Name:
[text your-name]

Last Name:
[text last-name]


What is your goal?
[radio radio-20 default:0 "Lose Weight" "Build Muscle"]

[submit "Continue Questionnaire"][multistep "2-5"]
 
 
<div id="bm"></div>

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s