enjoys/forms-recaptcha

enjoys/forms 的插件

3.0.0 2023-05-13 13:59 UTC

This package is auto-updated.

Last update: 2024-09-13 16:44:41 UTC


README

enjoys/forms 的插件

运行内置服务器查看示例

php -S localhost:8000 -t ./example .route

用法

// ...before code
// Optional. Set ID for form (for V2Invisible and V3) 
$form->setAttribute(AttributeFactory::create('id', uniqid()));
// Init reCaptcha
$captcha = new reCaptcha($Psr18_HttpClient, $Psr7RequestFactory, $Psr7StreamFactory);

$captcha->setOptions([
    'type' => V3::class, //V2Invisible, V2, V3
    'publicKey' => '...',
    'privateKey' => '...',
    'submitEl' => 'submit1',
    // more options ...
]);

$form->captcha($captcha);
$form->submit('submit1');
// more code...

全局选项

  • privateKey string required 私钥
  • publicKey string required 公钥
  • language string 语言 默认: en
  • type string 类型 默认: \Enjoys\Forms\Captcha\reCaptcha\Type\V2

reCAPTCHA v2

小部件选项

  • data-theme string dark|light 可选。小部件的颜色主题。 默认: light
  • data-size string compact|normal 可选。小部件的大小。 默认: normal
  • data-tabindex string 可选。小部件和挑战的 tabindex。如果页面上的其他元素使用 tabindex,应设置它以使用户导航更容易。 默认: null
  • data-callback string 可选。您回调函数的名称,在用户提交成功的响应时执行。g-recaptcha-response 令牌传递到您的回调。 默认: null
  • data-expired-callback string 可选。您回调函数的名称,当 reCAPTCHA 响应过期且用户需要重新验证时执行。 默认: null
  • data-error-callback string 可选。您回调函数的名称,当 reCAPTCHA 遇到错误(通常是网络连接)且无法继续直到连接恢复时执行。如果您在此处指定一个函数,您负责通知用户他们应该重试。 默认: null

不可见 reCAPTCHA 及 reCAPTCHA v3

一般选项

  • submitEl string 提交元素名称。另外,提交按钮 ID 不应该是 submit
  • 表单必须有 ID 属性。
  • type \Enjoys\Forms\Captcha\reCaptcha\Type\V2Invisible 或 V2Invisible::class 用于不可见 reCAPTCHA,\Enjoys\Forms\Captcha\reCaptcha\Type\V3 或 V3::class 用于 reCAPTCHA v3

小部件选项

  • data-badge string bottomright|bottomleft|inline 可选。重新定位 reCAPTCHA 徽章。'inline' 允许您使用 CSS 定位它。 默认: bottomright
  • data-size string invisible 可选。用于创建绑定到 div 的不可见小部件并程序化执行。 默认: null
  • data-tabindex string 可选。小部件和挑战的 tabindex。如果页面上的其他元素使用 tabindex,应设置它以使用户导航更容易。 默认: null
  • data-callback string 可选。您回调函数的名称,在用户提交成功的响应时执行。g-recaptcha-response 令牌传递到您的回调。 默认: null
  • data-expired-callback string 可选。您回调函数的名称,当 reCAPTCHA 响应过期且用户需要重新验证时执行。 默认: null
  • data-error-callback string 可选。您回调函数的名称,当 reCAPTCHA 遇到错误(通常是网络连接)且无法继续直到连接恢复时执行。如果您在此处指定一个函数,您负责通知用户他们应该重试。 默认: null