walkboy / yii2-hcaptcha
Yii2 hCaptcha widget
Installs: 4
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
pkg:composer/walkboy/yii2-hcaptcha
Requires
- php: ^8.0
- yiisoft/yii2: ^2.0.11
- yiisoft/yii2-httpclient: *
Requires (Dev)
- phpunit/phpunit: ^10.5.58
This package is auto-updated.
Last update: 2025-10-15 09:41:17 UTC
README
This package based on archived Yii2 Recaptcha Widget and adapted for hCaptcha.
Installation
The preferred way to install this extension is through composer.
Either run
composer require "walkboy/yii2-hcaptcha" "*"
or add
"walkboy/yii2-hcaptcha" : "*"
to the require
section of your application's composer.json
file.
-
Configure the component in your configuration file (web.php or main.php). The parameters siteKey and secret are optional. But if you leave them out you need to set them in every validation rule and every view where you want to use this widget. If a siteKey or secret is set in an individual view or validation rule that would overrule what is set in the config.
'components' => [ 'hCaptcha' => [ 'class' => \walkboy\hcaptcha\HCaptchaConfig', 'siteKey' => 'your siteKey', 'secret' => 'your secret', ], ... ],
- Add
HCaptchaValidator
in your model, for example:
public $verifyKey; public function rules() { return [ // ... [['verifyKey'], \walkboy\hcaptcha\HCaptchaValidator::class, 'secret' => 'your secret key', // unnecessary if hCaptcha is already configured 'uncheckedMessage' => 'Please confirm that you are not a robot.'], ]; }
Usage
For example:
<?= $form->field($model, 'verifyKey')->widget( \walkboy\hcaptcha\HCaptcha2::className(), [ 'siteKey' => 'your siteKey', // unnecessary is hCaptcha component was set up ] ) ?>
or without model
<?= \walkboy\hcaptcha\HCaptcha2::widget([ 'name' => 'verifyKey', 'siteKey' => 'your siteKey', // unnecessary is hCaptcha component was set up 'widgetOptions' => ['class' => 'col-sm-offset-3'], ]) ?>
- NOTE: Please disable ajax validation for hCaptcha field!