问题
I am using "contact form 7"
WordPress plugin.
I want to disable submit button on form submit and change text like
"Submitting...."
and enable on success or on error so the user can click again.
回答1:
Please use this code to disable the submit button.
jQuery('.wpcf7-submit').on('click',function(){
jQuery(this).prop("disabled",true); // disable button after clicking on button
});
As we know that the contact form 7
plugin returns various responses after submitting.
This is for mail sent event:
document.addEventListener( 'wpcf7mailsent', function( event ) {
jQuery(this).prop("disabled",false);// enable button after getting respone
}, false );
see all events of contact form 7
Updated:
document.addEventListener( 'wpcf7submit', function( event ) {
var status = event.detail.status;
console.log(status);
//if( status === 'validation_failed'){
jQuery('.wpcf7-submit').val("Send");
//}
}, false );
jQuery('.wpcf7-submit').on('click',function(){
jQuery(this).val("Submitting....");
});
Note: status
returns the responses like validation_failed
, mail_sent
, etc after form submitted.
来源:https://stackoverflow.com/questions/53760658/how-to-disable-submit-button-and-change-text-on-form-submit-at-wordpress-contac