- Custom alignment
- Centered by default
- Not jQuery dependent
- Not printable by default
- Development keys by default
- Better responsive Improvements
- Support for google reCaptcha and also hCaptcha
- Support for multiple validators, widgets and keys at the same time
The preferred way to install this extension is through composer.
Either run
$ composer require dynamikaweb/yii2-captcha "*"
or add
"dynamikaweb/yii2-captcha": "*"
to the require
section of your composer.json
file.
- View file
<?php
use dynamikaweb\captcha\Captcha;
?>
<?=Captcha::widget([
'siteKey' => 'XXX',
'name' => 'captcha',
'pos' => Captcha::POS_LEFT // or Captcha::POS_CENTER or Captcha::POS_RIGHT (optional)
'size' => Captcha::SIZE_COMPACT // or Captcha::SIZE_NORMAL (optional)
'type' => Captcha::TYPE_RECAPTCHA // or Captcha::TYPE_HCAPTCHA
])?>
- Model file
<?php
namespace app\models;
use dynamikaweb\captcha\CaptchaValidator;
class SomeModel extends yii\base\Model
{
public $captcha;
public function rules()
{
return [
[['captcha'], CaptchaValidator::classname(),
'type' => CaptchaValidator::TYPE_RECAPTCHA, // or CaptchaValidator::TYPE_HCAPTCHA
'siteKey' => 'XXX', // (optional)
'secret' => 'XXX'
]
];
}
}
- View file
<?php
use dynamikaweb\captcha\Captcha;
?>
<?=$form->attribute($model, 'captcha')->widget('dynamikaweb\captcha\Captcha')?>
- Model file
<?php
namespace app\models;
use dynamikaweb\captcha\CaptchaValidator;
class SomeModel extends yii\base\Model
{
public $captcha;
public function rules()
{
return [
[['captcha'], CaptchaValidator::classname(),
'type' => CaptchaValidator::TYPE_RECAPTCHA, // or CaptchaValidator::TYPE_HCAPTCHA
'secret' => 'XXX'
]
];
}
}
- View file
<?php
use dynamikaweb\captcha\Captcha;
?>
<?=$form->attribute($model, 'captcha')->widget('dynamikaweb\captcha\Captcha', [
'siteKey' => 'XXX',
'size' => Captcha::SIZE_COMPACT // or Captcha::SIZE_NORMAL (optional)
'pos' => Captcha::POS_LEFT // or Captcha::POS_CENTER or Captcha::POS_RIGHT (optional)
])?>
This project is under BSD-3-Clause license.