Just playing around with Wordpress / Contact Form 7
.
Is it possible to add custom javascript function on successful email send event?
Submit Button. A submit button is an essential component of a form. As you may know, HTML represents a submit button as an input element with submit type: <input type="submit">. You can use this HTML tag in a contact form of Contact Form 7, but you should use Contact Form 7’s own submit form tag instead.
To implement custom functionality in the Contact Form 7 plugin for WordPress. You can use any method from the below methods: This action hook is used to customize form or form value before sending the email using a plugin. In action hooks, we are passing an array that includes the form title and an array of submitted data.
With wpcf7_before_send_mail action hook, you can call a PHP function after Contact Form 7 submit. I am going to show you how to do that. First, create the custom PHP function that you want to execute after CF7 form submit: The $contact_data variable contains all the form data as an array format.
Just playing around with Wordpress / Contact Form 7. Is it possible / do you know how to add custom javascript function on successful email send event? simply add you JavaScript function to your page then find the Additional Settings field at the bottom of the contact form management page and use the on_sent_ok JavaScript action hook like so:
Just a quick note that on_sent_ok is deprecated.
Contact form 7 is now using event listeners, like this;
<script type="text/javascript">
document.addEventListener( 'wpcf7mailsent', function( event ) {
if ( '11875' == event.detail.contactFormId ) { // if you want to identify the form
// do something
}
}, true );
</script>
Then add this to the wp_footer action.
like this;
add_action( 'wp_footer', 'wp1568dd4_wpcf7_on_sent' );
function wp1568dd4_wpcf7_on_sent() {
// the script above
}
Contact Form 7 emits a number of Javascript events that bubble up to the document object. In version 4.1 they can be found in contact-form-7/includes/js/scripts.js. If you're using jQuery you can access those events like this:
$(document).on('spam.wpcf7', function () {
console.log('submit.wpcf7 was triggered!');
});
$(document).on('invalid.wpcf7', function () {
console.log('invalid.wpcf7 was triggered!');
});
$(document).on('mailsent.wpcf7', function () {
console.log('mailsent.wpcf7 was triggered!');
});
$(document).on('mailfailed.wpcf7', function () {
console.log('mailfailed.wpcf7 was triggered!');
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With