2012-07-03 50 views
1

我正在使用jquery驗證表單腳本,並需要添加一個驗證碼腳本。如果表單檢查返回true,則比我想運行驗證碼腳本來控制用戶輸入的值。我怎樣才能做到這一點?我的意思是我應該在哪裏寫驗證碼檢查腳本?謝謝。添加驗證碼檢查到jquery表單驗證

表單驗證如下:

$("#form1").validate({ 

    errorPlacement: function(error,element){           
      return true; 
      }, 
    errorClass: "invalid" 

}); 

驗證碼腳本如下:

$.post("post.php?"+$("#form1").serialize(), { 

     }, function(response){ 

     if(response==1) 
     { 
      $("#after_submit").html(''); 
      $("#Send").after('<label class="success" id="after_submit">Your message has been submitted.</label>'); 
      change_captcha(); 
      clear_form(); 
     } 
     else 
     { 
      $("#after_submit").html(''); 
      $("#Send").after('<label class="error" id="after_submit">Error ! invalid captcha code .</label>'); 
     } 


    }); 

回答

-1

可以在submitHandler檢查驗證碼的代碼。

$("#form1").validate({ 

    errorPlacement: function(error,element){           
      return true; 
      }, 
    errorClass: "invalid", 

    submitHandler: function() { 
     //you can add the recaptcha code here 
    } 

}); 

如果所有的驗證都成功了,那麼控件將在submitHandler中到達,在那裏您可以檢查您的recaptcha代碼。