如何在表单上实现新的隐形 reCAPTCHA?

How to implement the new invisible reCAPTCHA on form?

我正在尝试让新的 "invisible" 版本的 google reCAPTCHA 在我的表单上运行。

我正在使用 https://github.com/UndefinedOffset/silverstripe-nocaptcha

根据文档,您应该可以在 config.yml 中进行更改,我认为它是不可见的?

default_size: "invisible"

--

public function HelloForm() {
        $fields = new FieldList(
            new TextField('Name'),
            new EmailField('Email'),
            new TextareaField('Message')
        );
        $actions = new FieldList(
            new FormAction('doSubmitHelloForm', 'Submit')
        );

        $form = new Form($this, 'HelloForm', $fields, $actions);

        $form->enableSpamProtection()
            ->fields()->fieldByName('Captcha')
            ->setTitle("Spam protection")
            ->setDescription("Please tick the box to prove you're a human and help us stop spam.");

        return $form;
    }

config.yml

NocaptchaField:
  site_key: "MYKEYINHERE" #Your site key (required)
  secret_key: "MYKEYINHERE" #Your secret key (required)
  verify_ssl: true #Allows you to disable php-curl's SSL peer verification by setting this to false (optional, defaults to true)
  default_theme: "light" #Default theme color (optional, light or dark, defaults to light)
  default_type: "image" #Default captcha type (optional, image or audio, defaults to image)
  default_size: "invisible" #Default size (optional, normal, compact or invisible, defaults to normal)
  proxy_server: "" #Your proxy server address (optional)
  proxy_auth: "" #Your proxy server authentication information (optional)

但是验证码仍然显示,我是不是漏掉了什么? (请注意,我只是在我的本地开发机器 atm 上测试这个)。

好的,这里有 2 个问题。

  1. 我最初使用的是旧版本的 nocaptcha 模块。然后我升级到 0.3.0(发布这篇文章时的最新版本)并且验证码被隐藏了。

  2. 模块中有一个错误,这意味着它在提交表单时一直显示错误消息(说需要勾选验证码)。作者现已修复此问题,并将尽快将此版本标记为 0.4.0。

:)