Support » Plugin: Contact Form 7 » Events and redirections not working with functions.php

  • Hi,

    I found out that forms were not sending anymore because of the deprecation of on_sent_ok. I thought this was going to be a problem later this year.

    At this moment the forms are working, but nothing is being measured. Also redirection isn’t working anymore. If you look at the code below it was redirecting to the else-clause, so in this case: https://www.example.com/2. I’m sure the id is okay, so it doesn’t seem to recognise the id.

    I’ve added this to the functions.php:

    add_action( 'wp_footer', 'mycustom_wp_footer' );
    
    function mycustom_wp_footer() {    
    ?>
        <script type="text/javascript">
        document.addEventListener( 'wpcf7mailsent', function( event ) {
           if ( '2252' == event.detail.contactFormId ) { // Sends submissions on form 2252 to thank you page
            location = 'https://www.example.com';
            } else { 
                location = 'https://www.example.com/2';
            }
       }, false );
        
        document.addEventListener( 'wpcf7mailsent', function( event ) {
        if ( '2252' == event.detail.contactFormId ) {
            ga( 'send', 'event', 'Newsletter', 'Applied' );
        } else if ( '1842' == event.detail.contactFormId ) {
            ga( 'send', 'event', 'Contactform footer', 'Contact'); 
        }      
    }, false );
        </script>

    The events are not measured at all.

    Can you tell what is going wrong?

    Thanks!

    PS I haven’t added the url because I don’t want everyone “trying” this out. I’m happy to supply it direct/PM.

Viewing 4 replies - 1 through 4 (of 4 total)
Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Events and redirections not working with functions.php’ is closed to new replies.