vitalygallyamov/yii2-coinhive-captcha

Yii2 Coin-Hive captcha widget

0.0.5 2017-10-08 20:45 UTC

This package is not auto-updated.

Last update: 2025-07-19 07:40:49 UTC


README

Installation

The preferred way to install this extension is through composer.

  • Either run
php composer.phar require --prefer-dist "vitalygallyamov/yii2-coinhive-captcha" "*"

or add

"vitalygallyamov/yii2-coinhive-captcha" : "*"

to the require section of your application's composer.json file.

  • Sign up for an coin hive captcha API keys.

  • Configure the component in your configuration file (web.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' => [
    'chCaptcha' => [
        'class' => 'vitalygallyamov\yii2\chcaptcha\ChComponent',
        'siteKey' => 'your siteKey',
        'secretKey' => 'your secretKey'
    ],
    ...
  • Add ChCaptchaValidator in your model, for example:
public function rules()
{
  return [
      // ...
      [['captcha'], \vitalygallyamov\yii2\chcaptcha\ChCaptchaValidator::className()]
  ];
}

or simply

public function rules()
{
  return [
      // ...
      [[], \vitalygallyamov\yii2\chcaptcha\ChCaptchaValidator::className()]
  ];
}

Usage

For example:

<?= $form->field($model, 'captcha')->widget(
    \vitalygallyamov\yii2\chcaptcha\ChCaptcha::className(),
    [
        'siteKey' => 'lNpPfutvRjREJrNaQ5LslzyBW0O7mPtx',
        'hashes' => 2048
    ]
) ?>

or

<?= \vitalygallyamov\yii2\chcaptcha\ChCaptcha::widget([
    'siteKey' => 'lNpPfutvRjREJrNaQ5LslzyBW0O7mPtx',
    'hashes' => 1024,
    'widgetOptions' => ['class' => 'col-sm-offset-3']
]) ?>

or

<?= $form->field($model, 'captcha')->widget(\vitalygallyamov\yii2\chcaptcha\ChCaptcha::className()) ?>

or simply

<?= \vitalygallyamov\yii2\chcaptcha\ChCaptcha::widget(['name' => 'chCaptcha']) ?>

Resources