How to disable submit button and change text on form submit at Wordpress “contact form 7”

牧云@^-^@ 提交于 2019-12-23 05:26:13

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!