我又回来了。这是问题所在。在实施ReCaptcha 2.0时,我已经从Github下载了文件并完成了所有指示(很明显没有,或者我不会有问题)。我的表单会自动加载错误,显示"缺少输入 - 响应"在提交按钮的正上方。但是,我可以填写并提交表格,然后重定向到"谢谢你"页。如果我尝试在没有选中框的情况下提交表单,它会给出错误(这很好),但无论如何都会出现错误。我需要做什么?我真的很感激任何帮助。
这是我的代码:
<?php
require('recaptcha-master/src/autoload.php');
$siteKey = 'MY SITE KEY';
$secret = 'MY SECRET KEY';
$recaptcha = new \ReCaptcha\ReCaptcha($secret, new \ReCaptcha\RequestMethod\SocketPost());
$gRecaptchaResponse = $_POST['g-recaptcha-response']; //google captcha post data
$remoteIp = $_SERVER['REMOTE_ADDR']; //to get user's ip
$recaptchaErrors = ''; // blank variable to store error
$resp = $recaptcha->verify($gRecaptchaResponse, $remoteIp); //method to verify captcha
if ($resp->isSuccess()) {
// send mail or insert in db or do whatever you wish to
$emailbody = 'Name: '.$_POST['name']."\n"
.'Phone: '.$_POST['phone']."\n"
.'Email: '.$_POST['email']."\n"
.'Message: '.$_POST['message'];
mail('newsong80@maxxsouth.net', 'More Information', $emailbody);
echo "<meta http-equiv='refresh' content=\"0; url=thankyou.php\">";
} else {
$recaptchaErrors = $resp->getErrorCodes(); // set the error in varible
}
?>
**Here is my form:**
<form action="contact.php" method="POST" title="Contact us for more information">
<p><b>Name:<br>
</b>
<input name="name" type="text" required id="name" tabindex="1" value="" size="50" maxlength="50"/>
<br/> Phone:
<br>
<input name="phone" type="text" id="phone" tabindex="2" value="" size="50" maxlength="50"/><br/>
<b>E-mail:</b><br>
<input name="email" type="text" id="email" tabindex="3" value="" size="50" maxlength="25"/><br/>
<br>
<b>Message:</b><br/>
<textarea name="message" cols="60" rows="10" maxlength="150" id="message" tabindex="4"></textarea><br>
<br>
<div class="g-recaptcha" data-sitekey="MY SITE KEY"></div>
<br>
<?php
if ( isset( $recaptchaErrors[ 0 ] ) )
echo $recaptchaErrors[ 0 ];
?>
<p> </p>
<p><input name="submit" type="submit" formmethod="POST" onClick="MM_validateForm('name','','R','phone','','NisNum','email','','RisEmail','message','','R');return document.MM_returnValue" value="Submit">
</p>
</form>