有没有办法将验证码添加到WordPress中的自定义表单中,我已经浏览了一些插件,但它只允许在登录,评论表单等中添加验证码。
我使用了Google reCaptcha,我使用了这个脚本
<script type="text/javascript"
src="http://www.google.com/recaptcha/api/challenge?k=your_public_key">
</script>
<noscript>
<iframe src="http://www.google.com/recaptcha/api/noscript?k=your_public_key"
height="300" width="500" frameborder="0"></iframe><br>
<textarea name="recaptcha_challenge_field" rows="3" cols="40">
</textarea>
<input type="hidden" name="recaptcha_response_field"
value="manual_challenge">
</noscript>
它在联系页面上工作正常但是如果我点击提交它没有验证我应该在联系页面中放置什么代码,这样它就可以用于验证。
答案 0 :(得分:2)
您需要检查答案的验证,而不仅仅是使用验证码挑战来显示块。 https://web.archive.org/web/20121108134349/https://developers.google.com/recaptcha/docs/php
<?php
require_once('recaptchalib.php');
$privatekey = "your_private_key";
$resp = recaptcha_check_answer ($privatekey,
$_SERVER["REMOTE_ADDR"],
$_POST["recaptcha_challenge_field"],
$_POST["recaptcha_response_field"]);
if (!$resp->is_valid) {
// What happens when the CAPTCHA was entered incorrectly
die ("The reCAPTCHA wasn't entered correctly. Go back and try it again." .
"(reCAPTCHA said: " . $resp->error . ")");
} else {
// Your code here to handle a successful verification
}
?>