webbuilders-group / silverstripe-turnstile
使用CloudFlare的Turnstile提供的垃圾邮件防护和表单字段
1.1.1
2024-05-10 12:33 UTC
Requires
- silverstripe/framework: >=4.0,<6.0
- silverstripe/spamprotection: >=3.0,<5.0
Requires (Dev)
This package is auto-updated.
Last update: 2024-09-10 13:10:18 UTC
README
通过使用Cloudflare的Turnstile服务,为Silverstripe用户表单添加“垃圾邮件防护”字段。
维护者联系方式
- Ed Chipman (UndefinedOffset)
要求
- Silverstripe框架 ~4.0 或 ~5.0
- silverstripe/spamprotection ~3.0 或 ~4.0
安装
composer require webbuilders-group/silverstripe-turnstile
配置
该字段有多种配置选项,您必须设置从Cloudflare获取的site_key和secret_key。这些配置选项必须添加到您的站点yaml配置中,通常这是app/_config/config.yml
。
SilverStripe\SpamProtection\Extension\FormSpamProtectionExtension: default_spam_protector: WebbuildersGroup\Turnstile\Forms\TurnstileProtector #Set the default spam protector WebbuildersGroup\Turnstile\Forms\TurnstileField: site_key: '`TURNSTILE_SITE_KEY`' #Your site key (required) secret_key: '`TURNSTILE_SECRET_KEY`' #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, dark or auto, defaults to light) js_onload_callback: null #Onload callback to be called when the JS for Turnstile is loaded proxy_server: "`SS_OUTBOUND_PROXY_SERVER`" #Your proxy server address (optional) proxy_port: "`SS_OUTBOUND_PROXY_PORT`" #Your proxy server address port (optional) proxy_auth: "`SS_OUTBOUND_PROXY_AUTH`" #Your proxy server authentication information (optional)
添加字段标签
如果您想为验证码字段添加字段标签或帮助文本,可以这样做:
$form->enableSpamProtection() ->Fields() ->fieldByName('Captcha') ->setTitle('Spam protection') ->setDescription('Your description here');
添加自定义属性
Turnstile有几个其他选项,该模块没有提供挂钩来设置,但是您可以使用setAttribute
自行设置,例如
$form->enableSpamProtection() ->Fields() ->fieldByName('Captcha') ->setAttribute('data-action', 'action') ->setAttribute('data-cdata', 'payload') ->setAttribute('data-callback', 'yourChallengeJSCallback') ->setAttribute('data-expired-callback', 'yourExpiredJSCallback') ->setAttribute('data-error-callback', 'youErrorJSCallback') ->setAttribute('data-tabindex', 0);