Mark Wilson Mark Wilson - 21 days ago 5
jQuery Question

Contact Form 7 validation trigger event

When user clicks on submit button for the contact form 7 form, I want the page to scroll to the validation message section.

My approach:

I am using jQuery

on click
event for the submit button and on click scrolling the page to validation message section.

I am sure that it is not correct. Because on click it scrolls to the section but the message has not yet come through ajax.

So, is there a way to create an event when validation is done in contact form 7 and use that to scroll down.

Answer

Contact Form 7 triggers wpcf7:invalid in this case. You can use this trigger:

$(window).on('wpcf7:invalid', function() {
    // let's scroll
});

Source: https://github.com/wp-plugins/contact-form-7/blob/master/includes/js/scripts.js (Line: 109)

Comments