[英]problems using google invisible recaptcha icon
我的 codeigniter 项目中有一个使用 google 隐形 recaptcha 的表单,如下所示:
HTML
<html>
<head>
<script src="https://www.google.com/recaptcha/api.js" async defer></script>
<script>
function onSubmitInvisRecaptcha(token) {
document.getElementById("contact_us-form").submit();
}
</script>
</head>
<body>
<form id="contact_us-form" method="post" action="/info/contact_us">
<div>
<label>full name</label>
<input type="text" name="full_name" value="<?php echo $this->input->post('full_name'); ?>"/>
</div>
<div>
<button type="submit"
id="submit_btn"
class="btn my-other-styles g-recaptcha"
data-sitekey="<?php echo $sitekey; ?>"
data-callback="onSubmitInvisRecaptcha">
Submit
</button>
</div>
</form>
</body>
</html>
PHP
defined('BASEPATH') OR exit('No direct script access allowed');
class Info extends MY_Controller
{
function contact_us()
{
print_r($_POST);
}
}
从我的代码中,我有两个问题:(我希望可以在 1 个帖子中询问多个问题)
在页面中找不到recaptcha 图标。 .我检查了我在表单中使用的站点密钥与我在找到的相同。
在contact_us
函数中, print_r($_POST);
没有g-recaptcha-response
..
PS:该表单是使用 ajax 显示的另一个页面的一部分,因此该表单由另一个<div>
包装。
最后我从这个SO answer 中找到了答案。 该链接在一页中显示了多个验证码/表单的代码,但它很简单,可以根据我的需要进行理解和修改。
基本上,如果我理解正确,我的代码失败的原因是因为以下几点:
我需要使用单独的<div>
元素来应用 recaptcha 而不是提交按钮。
google recaptcha 将在页面加载时尝试找到指定的元素,否则,如果该元素仅在某些操作后出现或添加到页面中,我需要使用 javascript手动呈现和执行 grecaptcha。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.