由于无法在Google表格中使用reCAPTCHA来避免垃圾邮件,我试图在我的网站上使用它。我们的想法是拥有一个带有reCAPTCHA框架的页面,当验证结果正常时,提交"提交"按钮将加载带有Google表单的iframe。 这是我尝试过的,但是没有用,所以任何帮助都非常感激。
jQuery的:
$("button").click(function(){
var iframe = $("#dropform");
iframe.attr("src", iframe.data("src"));
});
php文件:
<form method="POST">
<!-- here you must input the site key, not the secret key -->
<div class="g-recaptcha" data-sitekey="xxxxx-xxxxx"></div>
<br/>
<input type="button" value="Submit">
</form>
<iframe id="dropform" src="https://docs.google.com/forms/d/e/xxxxxxxxxxxxx/viewform?embedded=true" width="760" marginwidth="0" height="1375" marginheight="0" frameborder="0">Loading...</iframe>
我也试过了:
js:
document.getElementById("dropform").disabled = true;
function enableform(){
document.getElementById("dropform").disabled = false;
}
php文件:
<form method="POST">
<!-- here you must input the site key, not the secret key -->
<div class="g-recaptcha" data-sitekey="xxxxxx-xxxxxxx" data-callback="enableform"></div>
<br/>
<iframe id="dropform" src="https://docs.google.com/forms/d/e/xxxxxxxxxxxxxxxxxx/viewform?embedded=true" width="760" marginwidth="0" height="1375" marginheight="0" frameborder="0">Loading...</iframe>
</form>
这是我用于秘密的PHP代码(不知道它是否正确,第一次使用reCAPTCHA):
<?php
$secret = "yyyyyyyyyyyyyyy";
$post = [
'secret' => $secret,
'response' => $_POST['g-recaptcha-response'],
'remoteip' => $_SERVER['REMOTE_ADDR']
];
$ch = curl_init('https://www.google.com/recaptcha/api/siteverify');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
$response = curl_exec($ch);
curl_close($ch);
$array = json_decode($response,true);
if($array['success'] == 1){
echo "success!" ;
}
else{
echo "Confirm you are not a robot";
}
?>
在完成reCAPTCHA检查之前,iframe已经可视化。我该如何解决?谢谢