【问题标题】:reCaptcha in OctoberCMS SmallContactForm does not work十月的 reCaptcha CMS SmallContactForm 不起作用
【发布时间】:2021-06-22 02:08:10
【问题描述】:

所以我尝试在 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 验证错误! 这个错误也显示了两次,但我不确定这是否重要。我不是机器人按钮渲染得很好,我也可以,但是当我发送表单时,我得到了错误。

我希望有人可以帮助我!提前致谢!

【问题讨论】:

    标签: html recaptcha octobercms


    【解决方案1】:

    所以我查看了 CMS 中的错误并得到了这个:

    file_get_contents(): https:// wrapper is disabled in the server configuration by allow_url_fopen=0
    

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

    【讨论】:

      猜你喜欢
      • 2019-05-02
      • 2017-06-24
      • 2018-04-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多