6
votes

I have used capcha in one of my forms. It always give verification code incorrect error.

Below is my code:

SchoolsController.php

public function actions() {
        return [
            'captcha' => [
                'class' => 'yii\captcha\CaptchaAction',
                'fontFile' => '@yii/captcha/SpicyRice.ttf',
                'padding' => '0',
            ]
        ];
    }

Model:

['verifyCode', 'captcha', 'captchaAction' => 'schools/captcha'],

View:

echo $form->field($modelSchoolRequestEarlyAccess, 'verifyCode')->widget(Captcha::className(), [
                        'options' => [
                            'placeholder' => 'Enter characters in the image',
                            'autocomplete' => 'off',
                            'maxlength' => 20 
                        ],
                        'captchaAction' => 'schools/captcha',
                        'template' => "<div class='field'><span><strong>*</strong>".Yii::t('frontend/quicksignup','VerifyCodeLabel').":</span></span>\n<div>{image}{input}<i class='refresh-code-icn' id='get-new-code'></i></div></div>"
                        ])->label(false); 

I have specified the captcha action as schools/captcha in model as well as view. But it always show verification incorrect.

What am I doing wrong??

2

2 Answers

1
votes

You wrote SchoolController.php and your route is to schools. So you probably need to adjust your route to school/captcha

0
votes

Did you add the rules?

   public function rules()
{
    $rules = parent::rules();
    $rules[] = ['captcha', 'required'];
    $rules[] = ['captcha', 'captcha'];
    return $rules;
}