After the new update of Contact form 7 plugin, ‘on_sent_ok‘ no longer works. So, after submitting the form, redirecting the user to a Thank You page or any other page becomes a bit tricky.
Now we have to use a Javascript function to redirect a user to any page after the form submit.
We have to use the below function on our active theme’s functions.php file to enable the Contact Form 7 redirect.
add_action( 'wp_footer', 'cf7_wp_footer' );
function cf7_wp_footer() {?>
<script type="text/javascript">
document.addEventListener( 'wpcf7mailsent', function( event ) {
if ( '10' == event.detail.contactFormId ) { // redirect for form id 10
location = 'https://www.example.com/thank-you/';
} else if ( '15' == event.detail.contactFormId ) { // redirect for form id 15
location = 'https://www.example2.com/';
} else { // redirect for all the other contact forms
location = 'https://www.example.com/thanks-so-much/';
}
}, false );
</script>
<?php }
Using the above functions, we can set multiple form redirect for multiple contact forms.




