Installation
The preferred way to install this extension is through composer., (*1)
php composer.phar require --prefer-dist "vitalygallyamov/yii2-coinhive-captcha" "*"
or add, (*2)
"vitalygallyamov/yii2-coinhive-captcha" : "*"
to the require
section of your application's composer.json
file.
* Sign up for an coin hive captcha API keys., (*3)
- 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, (*4)
public function rules()
{
return [
// ...
[[], \vitalygallyamov\yii2\chcaptcha\ChCaptchaValidator::className()]
];
}
Usage
For example:, (*5)
<?= $form->field($model, 'captcha')->widget(
\vitalygallyamov\yii2\chcaptcha\ChCaptcha::className(),
[
'siteKey' => 'lNpPfutvRjREJrNaQ5LslzyBW0O7mPtx',
'hashes' => 2048
]
) ?>
or, (*6)
<?= \vitalygallyamov\yii2\chcaptcha\ChCaptcha::widget([
'siteKey' => 'lNpPfutvRjREJrNaQ5LslzyBW0O7mPtx',
'hashes' => 1024,
'widgetOptions' => ['class' => 'col-sm-offset-3']
]) ?>
or, (*7)
<?= $form->field($model, 'captcha')->widget(\vitalygallyamov\yii2\chcaptcha\ChCaptcha::className()) ?>
or simply, (*8)
<?= \vitalygallyamov\yii2\chcaptcha\ChCaptcha::widget(['name' => 'chCaptcha']) ?>
Resources