下面的代码是我的网页上的表单代码,然后是test.php。问题是在$ _POST中没有发送recaptcha var。我已经确认了recaptcha的标签是在表单标签中,谷歌搜索引擎的调用就在脑海中。我无法找到我的表单没有发送var的原因。没有发送POST var中的recaptcha
<head>
<script src='https://www.google.com/recaptcha/api.js'></script>
</head>
<div id="contact" class="form-contain">
<fieldset>
<div id="message"></div>
<form method="post" action="js/test.php" name="contactform" id="contactform">
<div class="form-group">
<input name="name" id="name" type="text" value="" placeholder="Name" class="form-control" />
</div>
<div class="form-group">
<input name="email" id="email" type="text" value="" placeholder="Email" class="form-control" />
</div>
<div class="form-group">
<input name="phone" id="phone" type="text" value="" placeholder="Phone" class="form-control" />
</div>
<div class="g-recaptcha" data-sitekey="6LcMRQ0UAAAAACB1GVYh0oIQezzFcNmpsy0a7Sqx"></div>
<div class="form-group">
<button class="btn btn-primary" type="submit" id="cf-submit" name="submit">Send</button>
</div>
</form>
</fieldset>
</div>
test.php的:
<?php
$email;$comment;$captcha;
if(isset($_POST['email'])){
$email=$_POST['email'];
}if(isset($_POST['comment'])){
$email=$_POST['comment'];
}if(isset($_POST['g-recaptcha-response'])){
$captcha=$_POST['g-recaptcha-response'];
}
if(!$captcha){
echo '<h2>Please check the the captcha form.</h2>';
exit;
}
$secretKey = "Put your secret key here";
$ip = $_SERVER['REMOTE_ADDR'];
$response=file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=".$secretKey."&response=".$captcha."&remoteip=".$ip);
$responseKeys = json_decode($response,true);
if(intval($responseKeys["success"]) !== 1) {
echo '<h2>You are spammer ! Get the @$%K out</h2>';
} else {
echo '<h2>Thanks for posting comment.</h2>';
}
?>
你确定它没有设置,不只是空白或其他无效?如果你尝试执行echo isset($ _ POST ['g-recaptcha-response'])? “真”:“假”;',输出什么? – bugfroggy
@bugfroggy我通过添加echo var_dump($ _ POST)来检查;并返回 array(4){[“name”] => string(9)“Zack Tarr”[“email”] => string(28)“ztarr @ sy ....”[“phone”] => string(10)“812 ....”[“comments”] => string(1)“message”} –
在您的网站上,选中reCAPTCHA框但不提交表单。检查元素并在表单中查找ID为“g-recaptcha-response”的textarea。它应该在'g-recaptcha'类的'div'中。正确的结构应该是这样的:http://i.imgur.com/4A6q3Ao.png它存在于表单标签内吗?如果是这样,请更改其CSS,使其不再是'display:none',您可以轻松查看其内容。它里面有价值吗? – bugfroggy