Problems with contact form 7 - function on_sent_ok obsolete

1

I have some forms using the plugin contact form 7 and each one redirecting to a specific success page, I used on_sent_ok, however he does not want to run I went to check and found out that it is obsolete and the correct one now is to use the gift, but nothing happens when trying to put the gift.

I'm trying to use the following code, include it in functions.php:

add_action( 'wp_footer', 'mycustom_wp_footer' );

function mycustom_wp_footer() {
?>
<script>
document.addEventListener( 'wpcf7submit', function( event ) {
    if ( '238' == event.detail.contactFormId ) {
    location = 'http://www.site.com.br/sucesso1';
    }else if ( '235' == event.detail.contactFormId ) {
    location = 'http://www.site.com.br/sucesso2';
    }
}, false );
</script>
<?php
}
    
asked by anonymous 13.09.2017 / 17:20

1 answer

0

Try to replace wpcf7submit by just submit, because wpcf7submit is not an event.

add_action( 'wp_footer', 'mycustom_wp_footer' );

function mycustom_wp_footer() {
?>
    <script>
        document.addEventListener('wpcf7submit', function( event ) {
            if ( '238' == event.detail.contactFormId ) {
                window.location = 'http://www.site.com.br/sucesso1';
            }else if ( '235' == event.detail.contactFormId ) {
                window.location = 'http://www.site.com.br/sucesso2';
            }
        }, false );
    </script>
<?php
}
    
13.09.2017 / 17:27