php - Using ReCaptcha with jQuery Validate, giving correct response but gives error -


i'm using jquery validate registration form website recaptcha @ bottom. here script check form errors (edited relevant parts):

$(document).ready(function() {    jquery.validator.addmethod("checkcaptcha", function() {     var phpquery = $.ajax({url:"verify.php",       type: "post",       async: false,       data:{recaptcha_challenge_field:recaptcha.get_challenge(),recaptcha_response_field:recaptcha.get_response()},       success:function(resp) {         if (resp == 'false') {           console.dir(resp);           return false;         } else {           console.dir(resp);           return true;         }       }     });   },"");    $('#regform').validate({     rules:{       recaptcha_response_field:{required:true,checkcaptcha:true}     },     messages:{       recaptcha_response_field:{checkcaptcha:"your captcha response incorrect. please try again."}     }   }); }); 

what happens when enter correct recaptcha response , either click submit or tab out of response text field, true in console, throw false , prevent me submitting form.

what happens when incorrect recaptcha response entered, throw false it's supposed every letter type in, submit verify.php , return false. when done typing in correct recaptcha, doesn't recognize such , still returns false.

reloading recaptcha throws false, when correct response entered.

i know verify.php works correctly, because when <form> have action="verify.php," work (i.e., tell if entered correct recaptcha, regardless of how many times tried).

am missing something? there easier, reliable way this?

use onkeyup: false option inside .validate().

otherwise, every single time type 1 letter, run checkcaptcha method , send incomplete captcha code server. believe once incorrect captcha code sent, it's expired , can't send same code again.

either way, think it's best not send code server until after field complete.

$('#regform').validate({     onkeyup: false,     rules:{         recaptcha_response_field: {             required: true,             checkcaptcha: true         }     },     messages:{         recaptcha_response_field: {             checkcaptcha: "your captcha response incorrect. please try again."         }     } }); 

also, if captcha fails, you'll need trigger refresh new code.

recaptcha.reload(); 

inside success callback, perhaps...

success:function(resp) {     if (resp == 'false') {         console.dir(resp);         recaptcha.reload();  // new captcha code on failure         return false;     } else {         console.dir(resp);         return true;     } } 

Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

Function that returns a formatted array in VBA -