OctoberCMS SmallContactForm 中的 reCaptcha 不起作用

问题描述

所以我尝试在 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 中查找了错误并得到了这个:

directory

原来我的服务器不允许 url fopen。更改后,一切正常。我还写了插件的作者。他更改了源代码,因此它应该可以在没有 allow_url_fopen 参数的情况下工作。

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...