/, Tips and tricks/Contact form 7 redirect not working and How to set redirections – All Solved

Contact form 7 redirect not working and How to set redirections – All Solved

That’s an issue I am seeing everywhere in blogs and support forums. A common problem with Contact Form7 though it has so many solutions. Still it has many confusion? Cause Contact form 7 plugin can have multiple forms and wrong placement of the codes can redirect all forms to a single thank you page, But if you want different thank you page or destination page for each form ? That’s only one scenario I am talking. For Non-Coder people that’s a huge frustration how would they do it? With a popular plugin like contact form 7 everyone thought it would be available. Actually, it is but with another plugin. All issues I am solving here one by one for everyone.

First Solution for non-coder people or who just can use plugins in WordPress.

Don’t go right or left just straightforward use this plugin. The name is Contact Form 7 Redirection, click here to download.

After installind Contact Form7 Redirection plugin, you will have the option to redirect your every form to your desired page or link. Inside your form settings like the image below a new tab will appear called Redirect Settings. Set your URL  where you want them to redirect after submission. Just like a piece of cake.

Contact form 7 redirect not working

 

Now if this option, in any case, doesn’t work, we have to go manually through coding. Now I will show you how to do it. Don’t afraid I believe everyone will be able to do it who don’t know coding also.

1. First, we will use a code which will redirect all of our forms to a selected single thank you page or destination page. The code is given below

 

<script>
document.addEventListener( 'wpcf7mailsent', function( event ) {
location = 'http://example.com/';
}, false );
</script>

 

*** replace your URL with http://example.com ***

To use this code open your theme’s header.php file. Who knows how to use ftp or cpanel’s file manager just navigate to your theme’s folder and open your theme’s header.php file to edit.

or those are afraid of these things just go to website’s dashboard -> appearance -> Editor and open your theme’s header.php file

Now as I showed below with the image. Place the code before </head> tag.

Now if you try you will see all of your forms will redirect to a single thank you page.

2. Now if you want each form to redirect individual page or URL use the code below.

add_action( ‘wp_footer’, ‘cf7_thank_you_redirect’ );

function cf7_thank_you_redirect() {
?>
<script type=”text/javascript”>
document.addEventListener( ‘wpcf7mailsent’, function( event ) {
if ( ‘8’ == event.detail.contactFormId ) {
location = ‘http://example.com/first’;
} else if ( ‘4’ == event.detail.contactFormId ) {
location = ‘http://example.com/second’;
} else {
// do nothing
}
}, false );
</script>
<?php
}

you have to use this code in your theme’s functions.php file. Just like the screenshot below.

Here I have shown two redirection for two forms. If you have more than two forms just increase the else if part. My two forms id was 8 and 4 , Get your forms ids and replace with 8 or 4 also replace URLS with your own links instead of example.com.

How to get your contact form ids ? Just check the below image.

That’s it , I hope you guys will be helped with my blog. Please share or subscribe and if you want premium service we are open for 24/7 support. Thanks

Facebook Comments
By | 2018-01-14T17:46:58+00:00 January 12th, 2018|Plugins, Tips and tricks|0 Comments