Contact Form 7 AJAX Callback

Question :
Been searching around on this for a while and can't come up with any documentation to outline what i want to achieve.
I'm using wordpress and the Contact Form 7 plugin, all is working perfectly, what i want to achieve is to run some particular javascript upon form submit, I know we can use "on_sent_ok:" in the additional settings, but this only performs if the form is actually submitted.
What I'd like to do is to do some other javascript when the form doesn't submit ok, which throws the user back to the section which didn't validate.
Contact Form 7 AJAX Callback
Solution code for : Contact Form 7 AJAX Callback
Given the variety of responses on this topic the plugin developer seems to change their mind about how this should work every 5 minutes.
document.addEventListener( 'wpcf7mailsent', function( event ) {
  alert( "Fire!" );
}, false );
And the valid events are:
  • wpcf7invalid — Fires when an Ajax form submission has completed successfully, but mail hasn’t been sent because there are fields with invalid input.
  • wpcf7spam — Fires when an Ajax form submission has completed successfully, but mail hasn’t been sent because a possible spam activity has been detected.
  • wpcf7mailsent — Fires when an Ajax form submission has completed successfully, and mail has been sent.
  • wpcf7mailfailed — Fires when an Ajax form submission has completed successfully, but it has failed in sending mail.
  • wpcf7submit — Fires when an Ajax form submission has completed successfully, regardless of other incidents.
Reference: https://contactform7.com/dom-events/

No comments:

Post a Comment