2014-11-23 59 views
-1

我做了一個簡單的表格,使用最新的reCaptcha,但我不知道如何阻止發送表單,如果captcha錯誤改寫。Google新reCaptcha

<!DOCTYPE html> 
 
<html> 
 
<head> 
 
\t <title>reCaptcha</title> 
 
\t <script src='https://www.google.com/recaptcha/api.js'></script> 
 
</head> 
 
<body> 
 
<form action="validate.php" method="POST"> 
 
<div class="g-recaptcha" data-sitekey="My public key"></div> 
 
<input type="submit" value="Submit Form" style="width:100px;height:20px"> 
 
</form> 
 
</body> 
 
</html> 
 
</!DOCTYPE>

回答

0

你只需要取消默認事件從提交按鈕,提交表單數據時,返回的是成功。

$('input[type=submit]').click(function(e){ e.preventDefault(); $.post(//calling google api to verify it, function (data) { if (data.success) { $('form').submit(); } } ); });

+0

非常感謝! :) 您能編輯我的代碼並添加您的解決方案嗎? 我不知道我該如何使用它:https://developers.google.com/recaptcha/docs/verify – george 2014-11-23 16:25:41

+0

這不是一個好方法來檢查recaptcha,因爲你的方法不會阻止機器人動作。 (通過代碼提交表單) – benck 2014-11-24 15:08:29