wordpress contact form 7 – redirecting without submitting

Question

There is a wordpress page containing contact form 7 form. Upon submit, it shows the thanks message along with the download doc link.

We want to stop accepting certain email ids such as gmail. For the same we are using following script:

<script>
document.addEventListener( 'wpcf7submit', function( event ) {
    var foo = document.getElementsByName("Email")[0].value;
    var domain = foo.substring(foo.lastIndexOf("@") +1);

    if ( domain == 'gmail.com') {
        
     
    window.location.href = 'https://www.example.com';
    return false;

   
    }
}, false );
</script>

This script is working fine and redirecting ‘gmail’ users to another page, however it shows the thanks message for few seconds and then redirects. We do not want to show the thanks message at all and directly redirect him/her.

May be instead of ‘wpcf7submit’ we need to use some other event as the thanks message comes upon submission.

Any thoughts?

0
ajay 3 months 0 Answers 12 views 0

Leave an answer