Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
334 views
in Technique[技术] by (71.8m points)

jquery - reCAPTCHA plugin doesn't stop form submit

i have an html form on a wordpress site that uses the bws google captcha plugin which disables the submit until the reCAPTCHA has been completed. It works fine until the email field is completed upon which the submit button is enabled and the form can be submitted without completing the reCAPTCHA, my only thought is that is has something to do with JQuery code i am using to ensure the email field and confirm email field match (code below which works fine to check the fields match). Would this code be responsible and if so how would I stop it enabling the submit button until the reCAPTCHA has been completed, sorry I am new to this so not sure. Any help would be hugely appreciated.

jQuery(document).ready(function($) {

$(document).ready(function(){
    var $submitBtn = $("#regform button[type='submit']");
    var $emailBox = $("#email");
    var $confirmBox = $("#confirmemail");
    var $errorMsg =  $('<span id="error_msg">Emails do not match.</span>');

    // This is incase the user hits refresh - some browsers will maintain the disabled state    
 of the button.
    $submitBtn.removeAttr("disabled");

    function checkMatchingEmails(){
        if($confirmBox.val() != "" && $emailBox.val != ""){
            if( $confirmBox.val() != $emailBox.val() ){
                $submitBtn.attr("disabled", "disabled");
                $errorMsg.insertAfter($confirmBox);
            }
        }
    }

    function resetEmailError(){
        $submitBtn.removeAttr("disabled");
        var $errorCont = $("#error_msg");
        if($errorCont.length > 0){
            $errorCont.remove();
        }  
    }


    $("#confirmemail, #email")
         .on("keydown", function(e){
            /* only check when the tab or enter keys are pressed
             * to prevent the method from being called needlessly  */
            if(e.keyCode == 13 || e.keyCode == 9) {
                checkMatchingEmails();
            }
         })
         .on("blur", function(){                    
            // also check when the element looses focus (clicks somewhere else)
            checkMatchingEmails();
        })
        .on("focus", function(){
            // reset the error message when they go to make a change
            resetEmailError();
        })

});
});
question from:https://stackoverflow.com/questions/66054215/recaptcha-plugin-doesnt-stop-form-submit

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...