PHPackages                             giantbits/yii2-crelish-recaptcha - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Validation &amp; Sanitization](/categories/validation)
4. /
5. giantbits/yii2-crelish-recaptcha

ActiveYii2-extension[Validation &amp; Sanitization](/categories/validation)

giantbits/yii2-crelish-recaptcha
================================

Google reCAPTCHA v3 integration for Yii2 with automatic token refresh. Works seamlessly with AJAX/PJAX forms.

v1.0.0(6mo ago)070MITPHPPHP &gt;=7.4

Since Dec 15Pushed 6mo agoCompare

[ Source](https://github.com/smeyerme/yii2-crelish-recaptcha)[ Packagist](https://packagist.org/packages/giantbits/yii2-crelish-recaptcha)[ Docs](https://github.com/giantbits/yii2-crelish-recaptcha)[ RSS](/packages/giantbits-yii2-crelish-recaptcha/feed)WikiDiscussions main Synced today

READMEChangelogDependencies (2)Versions (2)Used By (0)

Yii2 Crelish reCAPTCHA v3
=========================

[](#yii2-crelish-recaptcha-v3)

Google reCAPTCHA v3 integration for Yii2 and Crelish CMS.

Features
--------

[](#features)

- **reCAPTCHA v3 support** - Invisible verification, no user interaction required
- **Automatic token refresh** - Solves the common expired token issue with AJAX/PJAX forms
- **Score-based validation** - Configure minimum score threshold
- **PJAX compatible** - Works seamlessly with Yii2 PJAX widgets
- **Simple integration** - Just add widget and validator to your forms

Installation
------------

[](#installation)

```
composer require giantbits/yii2-crelish-recaptcha
```

Configuration
-------------

[](#configuration)

Add the component to your application config:

```
'components' => [
    'recaptcha' => [
        'class' => \giantbits\crelish\recaptcha\RecaptchaConfig::class,
        'siteKey' => 'YOUR_RECAPTCHA_V3_SITE_KEY',
        'secret' => 'YOUR_RECAPTCHA_V3_SECRET_KEY',
        'scoreThreshold' => 0.5, // optional, default 0.5 (0.0 = bot, 1.0 = human)
    ],
]
```

Or use environment variables:

```
'recaptcha' => [
    'class' => \giantbits\crelish\recaptcha\RecaptchaConfig::class,
    'siteKey' => $_ENV['RECAPTCHA_SITE_KEY'],
    'secret' => $_ENV['RECAPTCHA_SECRET_KEY'],
],
```

Usage
-----

[](#usage)

### 1. Add the attribute to your model

[](#1-add-the-attribute-to-your-model)

```
class ContactForm extends Model
{
    public $name;
    public $email;
    public $message;
    public $recaptcha; // Add this attribute

    public function rules()
    {
        return [
            [['name', 'email', 'message'], 'required'],
            ['email', 'email'],
            // Add the validator
            ['recaptcha', \giantbits\crelish\recaptcha\RecaptchaValidator::class],
        ];
    }
}
```

### 2. Add the widget to your form

[](#2-add-the-widget-to-your-form)

**With ActiveForm (PHP):**

```
