JavaScript help with Contact Form 7

I am trying to figure out how to have one particular contact form redirect to a URL

Per Contact Form 7 instructions, I am to insert the following JavaScript in the appropriate place. I’m just not sure what teh “appropriate” place is.

I added the following on the actual page.
I will send my credentials following this post.

document.addEventListener( ‘wpcf7submit’, function( event ) {
if ( ‘3138’ == event.detail.contactFormId ) {
alert( “The contact form ID is 3138.” );
// do something productive
}
}, false );

Hi there,

I have tried to check the page that you linked but it requires a password for it to be accessed even if I have logged in.

For the meantime, please try this in the functions.php of the child theme:

function add_script() {
    if (is_page('xx') ):
    ?>
        <script>
            document.addEventListener( 'wpcf7submit', function( event ) {
                if ( '3138' == event.detail.contactFormId ) {
                    alert( "The contact form ID is 3138." );
                    // do something productive
                }
            }, false );
        </script>
    <?php
    endif;
}
add_action('wp_head', 'add_script');

Please change xx to the ID of the page where you want the code to be added.

Hope this helps.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.