Page redirect help

Hi there,

I’m using Contact Form 7 for my forms. One of the forms currently has a “on_sent_ok” directive to automatically redirect the page to a custom ‘thank you’ page.

I’ve heard that “on_sent_ok” is being deprecated at the end of 2017, and that page redirects should be handled using DOM events in future.

I’ve added the following to my child functions.php, but the page redirection doesn’t work. Any thoughts?

add_action( 'wp_footer', 'mycustom_wp_footer' );
 
function mycustom_wp_footer() {
?>
<script type="text/javascript">
document.addEventListener( 'wpcf7mailsent', function( event ) {
    if ( ‘5919’ == event.detail.contactFormId ) {
    location = 'https://kexino.com/thank-you';
}, false );
</script>
<?php
}

Hi,

I can see pretty quotes in your conditional statement. Please try this code instead.


add_action( 'wp_footer', 'mycustom_wp_footer' );
 
function mycustom_wp_footer() {
?>
<script type="text/javascript">
document.addEventListener( 'wpcf7mailsent', function( event ) {
    if ( '5919' == event.detail.contactFormId ) {
    location = 'https://kexino.com/thank-you';
}, false );
</script>
<?php
}

Hope that helps.

Hi,

Thanks for finding those pretty quotes - missed those.

I’ve tried the new script but it’s still not working. I’ve flushed caches, etc. without any success. Anything else you can think of that I could try?

Hi there,

Would you mind providing the link to your site so that we can check it?

Thank you.

Sure - it’s https://kexino.com

Hello There,

​To assist you better with this issue, would you mind providing us the url of your site with login credentials so we can take a closer look? This is to ensure that we can provide you with a tailored answer to your situation. Once you have provided us with your URL, we will be happy to assist you with everything.

To do this, you can create a secure note with the following info:
– Link to your site
– WordPress Admin username / password

Thank you.

Login details here

Hi There,

There is JS error on the code. Missing closing }. Should be like below.

add_action( 'wp_footer', 'mycustom_wp_footer' );
 
function mycustom_wp_footer() {
?>
<script type="text/javascript">
document.addEventListener( 'wpcf7mailsent', function( event ) {
    if ( '5919' == event.detail.contactFormId ) {
        location = 'https://kexino.com/thank-you';
     } // This is missing. Closing for if statement
}, false );
</script>
<?php
}

Update the code and try again.

That’s it! Perfect.

Thank you so much.

You’re welcome.