skip to Main Content

I have a form that’s inserted into a template using shortcode

<?php echo do_shortcode('[contact-form-7 id="370" title="Contact form 1"]') ?>

I’m trying to setup an event so that when the form is submitted I can redirect the user to another page. I’m using the following;

<script>
document.addEventListener( 'wpcf7mailsent', function( event ) {
  location = 'http://example.com/';
}, false );
</script>

The problem is, when you submit the form, the whole page is reloaded so the event is never triggered because the form isn’t submitted via an ajax call.

This is the first time I’m trying to integrate a form into WordPress, so I think I may have missed something. There are no errors in the developer console in Chrome.

2

Answers


  1. Chosen as BEST ANSWER

    My theme was missing;

    Adding that solved the issue.


  2. Somewhere in your theme (check functions.php) or your wp-config.php file, you need to look for and remove the following:

    functions.php

    add_filter( 'wpcf7_load_js', '__return_false' );
    

    config.php

    define( 'WPCF7_LOAD_JS', false );
    

    These lines would prevent the default behavior of CF7.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search