首页 > 解决方案 > 十月的 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 验证错误! 此错误也显示两次,但我不确定这是否重要。我不是机器人按钮渲染得很好,我也能正常工作,但是当我发送表单时,我得到了错误。

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

标签: htmlrecaptchaoctobercms

解决方案


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

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

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


推荐阅读