在表单验证中包含验证码

时间:2016-04-01 17:52:41

标签: javascript captcha

如何将此代码集成到以下形式的验证条件中:

$("form").clientSideCaptcha({
            input: "#captchaText", 
            display: "#captcha",
            pass : function() { alert("Passed!"); return false; },
            fail : function() { alert("Please enter the text shown below");
    document.contactForm.textcaptcha.focus();
    return false; }
        });

1 个答案:

答案 0 :(得分:0)



$(document).ready(function() {
  $("#form").submit(function(event) {
    //check for validCaptcha
    var validCaptcha = $("#form").clientSideCaptcha({
      input: "#captchaText",
      display: "#captcha",
      pass: function() {
        return true;
      },
      fail: function() {
        document.contactForm.textcaptcha.focus();
        return false;
      }
    });
    //invalid captcha - stop form submission
    if (!validCaptcha) {
      event.preventDefault();
    }
   }
});