T
T
tiqq2018-10-02 16:49:05
Yii
tiqq, 2018-10-02 16:49:05

Why does reCaptcha in yii2 always give an error?

Hello. I use this widget, installed it as in the instructions, everything is displayed and marked on the site, but when I click register, the server always returns "Еhe verification code is incorrect" although everything was marked correctly.
Model:

class SignupForm extends Model {
  ...    
  public $reCaptcha;

    public function rules()
    {
        return [
           ...
            [['reCaptcha'], \himiklab\yii2\recaptcha\ReCaptchaValidator::className(), 'secret' => 'Секректный ключ']
        ];
    }
  ...
}

In the view:
<?= $form->field($model, 'reCaptcha')->widget(
  \himiklab\yii2\recaptcha\ReCaptcha::className(),
  [
    'siteKey' => 'Ключ сайта'
  ]
) ?>

In controller:
public function actionSignup()
    {
        $form = new SignupForm();
        
        if ($form->load(Yii::$app->request->post()) && $form->validate()) {
            try{
                $user = $form->signup($form);
                Yii::$app->session->setFlash('success', 'Проверьте почту, мы отправили туда код подтверждения.');
                $form->sentEmailConfirm($user);
                return $this->actionSignupTokenSent();
            } catch (\RuntimeException $e){
                Yii::$app->errorHandler->logException($e);
                Yii::$app->session->setFlash('error', $e->getMessage());
            }
        }

        return $this->render('signup', [
            'model' => $form,
        ]);
    }

What am I doing wrong?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question