Reputation: 533
I need to prevent Contact Form 7 WordPress plugin from clearing form on successful submission. I want user to be able to keep editing the form (and possibly to resubmit it again).
Thanks.
Upvotes: 1
Views: 3451
Reputation: 533
I actually found a solution. You can just attach an event handler to reset
event and then do e.preventDefault()
.
setTimeout( function(){
$( '.my-form form' ).on( 'reset', function(e) {
e.preventDefault();
});
},500)
It didn't work without the timeout, but this should be safe enough. Not many users can fill a form in under 0.5 second :-)
Maybe not a perfect solution but it works for my case.
EDIT: Here is a new version without the setTimeout (thanks to @Jan Myszkier)
$(document).on('reset', '.my-form form', function(e) {
e.preventDefault();
});
Upvotes: 3
Reputation: 2744
In JS wp-content/plugins/contact-form-7/includes/js/scripts.js
around line 300 there's ajaxSuccess function described with the following piece:
if ( 'mail_sent' == data.status ) {
$form.each( function() {
this.reset();
} );
wpcf7.toggleSubmit( $form );
}
which might be just what you're looking for because this.reset();
resets the field one by one within the form after successful status.
EDIT: Following your information you want to modify the behaviour but not change the plugin, you can use the events that come with CF7.
https://contactform7.com/dom-events/
add wpcf7submit
watcher to store the data in the localstorage and add another watcher (wpcf7mailsent
this time ) to write the data back to the form.
Upvotes: 0