Reputation: 513
I'm using Wordpress (5.2.2) and Contact Form 7. How can I reset only certain fields on submit?
The default action on successful submit is to clear all of the form fields. I located what appears to be the call to reset in public_html/wp-content/plugins/contact-form-7/includes/js/scripts.js and commented out the indicated three lines,
if ( 'mail_sent' == data.status ) {
// $form.each( function() {
// this.reset();
// } );
wpcf7.toggleSubmit( $form );
}
which appears to now prevent resetting of all of the fields when the user clicks "send". However, I have a couple of pull-down selection fields ( [select id "opt1" "opt2" ... ] ) which I need to reset. Is there a way I can do this?
Upvotes: 0
Views: 2443
Reputation: 94
if ( 'mail_sent' == data.status ) {
$form.each( function() {
$.each( $(this)[0], function() {
if (!($(this).hasClass("noResetOnMailSent"))){
$(this).not(':button, :submit, :reset, :hidden').val('').prop('checked', false).prop('selected', false);
}
} );
} );
this issue already solved on official site of WordPress. check here
https://wordpress.org/support/topic/how-to-not-clear-or-autofill-certain-fields-after-submission/
Upvotes: 1