html - 十月的 reCaptcha CMS SmallContactForm 不起作用
问题描述
所以我尝试在 OctoberCMS 中将 reCaptcha v2 实施到我的表单中。为此,Janvince 的 SmallContactForm 插件提供了一个设置区域,可以在其中存储密钥和站点密钥。它还实现了所需的脚本。最后,我的代码看起来像这样
<form method="POST" action="LINK" accept-charset="UTF-8" class="form-group" id="scf-form-id-contactForm" enctype="multipart/form-data"><input name="_handler" type="hidden" value="contactForm::onFormSend"><input name="_session_key" type="hidden" value="sessionkey"><input name="_token" type="hidden" value="token">
<div class="form-group"><label class="control-label required" for="contactForm-name" >Name</label><input id="contactForm-name" class="form-control" name="name" type="text" required=""></div>
<div class="form-group"><label class="control-label required" for="contactForm-email" >Email</label><input id="contactForm-email" class="form-control" name="email" type="email" required=""></div>
<div class="form-group"><label class="control-label " for="contactForm-betreff" >Betreff</label><input id="contactForm-betreff" class="form-control" name="betreff" type="text"></div>
<div class="form-group"><label class="control-label required" for="contactForm-nachricht" >Ihre Nachricht</label><textarea id="contactForm-nachricht" class="form-control" name="nachricht" rows="5" required=""></textarea></div>
<div id="_protect-wrapper-contactForm" class="form-group _protect-wrapper"><label class="control-label">Please clear this field</label><input type="hidden" name="_form_created" value="ididddhcfi"><input id="_protect-contactForm" name="_protect" class="_protect form-control" value="http://"></div>
<script>
document.getElementById('_protect-contactForm').setAttribute('value', '');
document.getElementById('_protect-wrapper-contactForm').style.display = 'none';
</script>
<div class="form-group">
<div class="g-recaptcha" data-sitekey="data-sitekey"></div>
</div>
<div id="submit-wrapper-contactForm" class="form-group"><button type="submit" data-attach-loading class="oc-loader bg-innotechblue text-white font-bold rounded px-4 py-2">Send</button></div>
</form>
<script src='https://www.google.com/recaptcha/api.js' async defer></script>
后台功能:
if( Settings::getTranslated('add_google_recaptcha') ) {
try {
$response=json_decode(file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=".Settings::get('google_recaptcha_secret_key')."&response=".post('g-recaptcha-response')."&remoteip=".$_SERVER['REMOTE_ADDR']), true);
} catch(\Exception $e) {
Log::error($e->getMessage());
$errors[] = e(trans('janvince.smallcontactform::lang.settings.antispam.google_recaptcha_error_msg_placeholder'));
}
我已经仔细检查了我是否切换了站点密钥和密钥。我还尝试在表单上方和后面手动实现脚本,但我总是收到错误: Google reCAPTCHA 验证错误! 此错误也显示两次,但我不确定这是否重要。我不是机器人按钮渲染得很好,我也能正常工作,但是当我发送表单时,我得到了错误。
我希望有一个人可以帮助我!提前致谢!
解决方案
所以我查找了 CMS 中的错误并得到了这个:
file_get_contents(): https:// wrapper is disabled in the server configuration by allow_url_fopen=0
原来我的服务器不允许 url fopen。更改后,一切正常。我还写了插件的作者。他更改了源代码,因此它应该可以在没有 allow_url_fopen 参数的情况下工作。
推荐阅读
- python - 项目中所有自动字段的 django 重置序列
- python - 如何在python烧瓶中获取具有本地时区的模板文件的修改日期
- swiftui - SwiftUI - 如何正确重新加载 @ObservableObject 对象
- spacy - 在多个 GPU 上运行 spacy 以预测 ner
- apache - 获取 405 - 通过 BlueImp FileUpload 上传图像时某些请求上不允许的方法
- jwt - Auth0 中的过期 JWT
- bash - 捕获嵌入在 bash 函数中的对话框调用的结果
- amazon-web-services - 访问 lambda (Python) 代码中的 AWS 阶跃函数错误
- java - 无效的标头签名;读取 0x7061632C65746144,预期 0xE11AB1A1E011CEG0 - 您的文件似乎不是有效的 OLE2 文档]]
- css - 在 Framer Motion 退出动画完成之前,在路径更改时移除 CSS 模块