Problems with contact form 7 - obsolete on_sent_ok function

Asked

Viewed 414 times

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 it does not work I went to check and found that it is obsolete and the correct 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
}

2 answers

0

wpcf7invalid - Triggers when an Ajax form submission is successfully completed, but the email was not sent because there are fields with invalid entry.

wpcf7spam - Fires when an Ajax form submission is successfully completed, but the email was not sent because a possible spam activity was detected. wpcf7mailsent - Fires when an Ajax form submission is completed successfully and the email is sent.

wpcf7mailfailed - Fires when an Ajax form submission has been completed successfully, but failed to send email.

wpcf7submit - Fires when an Ajax form submission is successfully completed regardless of other incidents.

source: https://contactform7.com/dom-events/

0

Try replacing wpcf7submit with only Ubmit, 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
}
  • Still nothing returns so as if it were get in the url this parameter site.com.br/#wpcf7-f238-p242-O1

  • I made a change, if it doesn’t work I will remove my reply @Fernando

  • didn’t work I thought it was by conflict so I adapted the code, but so far nothing

  • add_action( 'wp_footer', 'mycustom_wp_footer' ); Function mycustom_wp_footer() { ? > <script> var $Jquery = jQuery.noConflict() $Jquery(Document.addeventlistener('wpcf7submit', Function( Event ) { if ( '238' == Event.detail.contactFormId ) { window.Location = 'http://www.site.com.br/success1'; }Else if if ( '235' == Event.detail.contactFormId ) { window.Location = 'http://www.site.com.br/success2'; } }, false ); </script> <? php }

Browser other questions tagged

You are not signed in. Login or sign up in order to post.