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,
    'themeV2' => RecaptchaV2Theme::Dark,
    'badgeV3' => RecaptchaV3Badge::Hidden,
    'container' => [
        'useContainer' => false,
    ],
],

General

siteKeyV2 string
$_ENV['RECAPTCHA_SITE_KEY_V2'], or '' if unset
Public site key for RecaptchaV2Field, used as the fallback when a field doesn't call withSiteKey().
secretV2 string
$_ENV['RECAPTCHA_SECRET_V2'], or '' if unset
Secret key used to verify v2 tokens server-side, unless a rule overrides it with its own secret.
siteKeyV3 string
$_ENV['RECAPTCHA_SITE_KEY_V3'], or '' if unset
Public site key for RecaptchaV3Field, used as the fallback when a field doesn't call withSiteKey().
secretV3 string
$_ENV['RECAPTCHA_SECRET_V3'], or '' if unset
Secret key used to verify v3 tokens server-side, unless a rule overrides it with its own secret.
verifyUrl string
'https://www.google.com/recaptcha/api/siteverify'
Google's siteverify endpoint used by RecaptchaClient.
sendRemoteIp bool
false
Include the visitor's IP address in verification requests, unless a rule overrides it with its own sendRemoteIp.
themeV2 RecaptchaV2Theme
RecaptchaV2Theme::Light
App-wide default theme for every RecaptchaV2Field (Light or Dark), unless a field overrides it with ->withTheme().
sizeV2 RecaptchaV2Size
RecaptchaV2Size::Normal
App-wide default size for every RecaptchaV2Field (Normal, Compact, or Invisible), unless a field overrides it with ->withSize().
typeV2 RecaptchaV2Type
RecaptchaV2Type::Image
App-wide default challenge type for every RecaptchaV2Field (Image or Audio), unless a field overrides it with ->withType().
badgeV3 RecaptchaV3Badge
RecaptchaV3Badge::BottomRight
App-wide default badge for every RecaptchaV3Field (BottomRight, BottomLeft, or Hidden), unless a field overrides it with ->withBadge().

Container Defaults

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

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