Hi, I have a captcha field in an application form, that correctly works, and one in the login form of the Users
module, that does not work. In the login form I wrote:
<?= $form->field($user, 'captcha')->widget(\yii\captcha\Captcha::className(), [
'captchaAction' => 'user/captcha', // Important, otherwise no image shown.
'template' => '...',
]); ?>
In the User model I wrote:
class User extends ActiveRecord implements IdentityInterface
{
public $captcha;
public function rules()
{
return [
...
['captcha','captcha'],
];
}
In the actions()
method of the UserController
I wrote:
public function actions()
{
return [
'captcha' => [
'class' => 'yii\captcha\CaptchaAction',
],
];
}
I also added this code in the behaviors()
method:
public function behaviors()
{
return [
'access' => [
'class' => AccessControl::className(),
'rules' => [
[
'actions' => ['captcha'],
'allow' => true,
],
],
]
];
}
Any idea?
Thanks