我试图像这样验证ReCaptcha,但它不起作用。它不会发送电子邮件,当点击“我不是机器人”时,没有任何反应。
if(trim($_POST['getResponse']) == '') {
$hasError = true;
} else {
$getResponse = trim($_POST['getResponse']);
}
我的ReCaptcha PHP代码
<div class="form-group">
<div class="g-recaptcha" data-sitekey="mykeyhere"></div>
<span class="help-block" style="display: none;">Kinnita,et sa ei ole robot.</span>
</div>
<span class="help-block" style="display: none;">Sisesta turvakood.</span>
</div>
<div class="actions">
<input type="submit" value="<?php _e('Saada', 'bootstrapwp'); ?>" name="submit" id="submitButton" class="btn btn-primary" title="Saada!" />
<input type="reset" value="<?php _e('Tühjenda väljad', 'bootstrapwp'); ?>" class="btn btn-danger" title="Tühjenda väljad." />
</div>
由于
答案 0 :(得分:0)
好的,用这段代码搞定了
if(isset($_POST['g-recaptcha-response'])){
$captcha=$_POST['g-recaptcha-response'];
}
if(!$captcha){
echo '<h2>Please check the the captcha form.</h2>';
exit;
}
$response=file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=key&response=".$captcha."&remoteip=".$_SERVER['REMOTE_ADDR']);
if($response.success==false)
{
echo '<h2>You are spammer ! Get the @$%K out</h2>';
}else
{
echo '<h2>Thanks for posting comment.</h2>';
}
现在唯一的问题是错误和成功消息显示在另一个页面上,如何在表单中显示这些错误和成功消息?