Answer the question
In order to leave comments, you need to log in
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' => 'Секректный ключ']
];
}
...
}
<?= $form->field($model, 'reCaptcha')->widget(
\himiklab\yii2\recaptcha\ReCaptcha::className(),
[
'siteKey' => 'Ключ сайта'
]
) ?>
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,
]);
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question