Home » Jquery » javascript – Making a condition out of the addEventListener('wpcf7mailsent') CF7

javascript – Making a condition out of the addEventListener('wpcf7mailsent') CF7

Posted by: admin February 22, 2020 Leave a comment

Questions:

I have here a code that triggers when a particular CF7 form is submitted

document.addEventListener( 'wpcf7mailsent', function( event ) {
    if(event.detail.contactFormId == '11164') {
    jQuery('.pop_timer_box').hide();
    }
}, false );

but how can I make this a condition like

if (wpcf7mailsent) {
   do this
} elseif (wpcf7mailfail) {
   do this
}

Thanks for the help!!!

How to&Answer:

Just add a second event listener for failed.

document.addEventListener( 'wpcf7mailfailed ', function( event ) {
    alert( "Mail Failed Event" ); // Make this whatever you want.
}, false );

Contact Form 7 Documentation