reCAPTCHA

reCAPTCHA

Google reCAPTCHA v2 & v3 fields & validation

Configuration

Set your site keys and secret keys via environment variables or directly in config/params.php:

'yiirocks/recaptcha' => [
    'siteKeyV3' => $_ENV['RECAPTCHA_SITE_KEY_V3'],
    'secretV3' => $_ENV['RECAPTCHA_SECRET_V3'],
    'sendRemoteIp' => true,
    'container' => [
        'useContainer' => false,
    ],
],

General

siteKeyV2 string
Public site key for RecaptchaV2Field, used as the fallback when a field doesn't call withSiteKey(). Default: $_ENV['RECAPTCHA_SITE_KEY_V2'], or '' if unset.
secretV2 string
Secret key used to verify v2 tokens server-side, unless a rule overrides it with its own secret. Default: $_ENV['RECAPTCHA_SECRET_V2'], or '' if unset.
siteKeyV3 string
Public site key for RecaptchaV3Field, used as the fallback when a field doesn't call withSiteKey(). Default: $_ENV['RECAPTCHA_SITE_KEY_V3'], or '' if unset.
secretV3 string
Secret key used to verify v3 tokens server-side, unless a rule overrides it with its own secret. Default: $_ENV['RECAPTCHA_SECRET_V3'], or '' if unset.
verifyUrl string
Google's siteverify endpoint used by RecaptchaClient. Default: 'https://www.google.com/recaptcha/api/siteverify'.
sendRemoteIp bool
Include the visitor's IP address in verification requests, unless a rule overrides it with its own sendRemoteIp. Default: false.

Container Defaults

Applied to every field's wrapper unless overridden per-field via ->useContainer(), ->containerTag(), or ->containerAttributes() — see v2 and v3.

container.useContainer bool
Enable/disable the wrapper element. Default: true.
container.tag string
Wrapper tag. Default: 'div'.
container.attributes array
Wrapper HTML attributes. Default: ['class' => 'mb-3'].