Hello,
I’m new in Yii, and I’m tying to learn it from documentation. And I have difficulties with validation error in Login form.
I have out-of-the-box controller like this:
` $model = new LoginForm();
if ($model->load(Yii::$app->request->post()) && $model->login()) {
return $this->goBack();
}
$model->password = '';
return $this->render('index', [
'model' => $model,
]);`
index layout:
`$form = ActiveForm::begin([‘id’ => ‘login-form’,‘action’=>‘login’]);
?>
<?= $form->field($model, 'email')->input('email'); ?>
<?= $form->field($model, 'password')->passwordInput() ?>
<div class="form-group">
<?= Html::submitButton('Enter', ['class' => 'btn btn-primary', 'name' => 'login-button']) ?>
</div>
<?php
ActiveForm::end();`
And in Model I have code to validate password
`public function validatePassword($attribute, $params)
{
if (!$this->hasErrors()) {
$user = $this->getUser();
if (!$user || !$user->validatePassword($this->password)) {
$this->addError($attribute, 'Incorrect username or password.');
}
}
}`
Than when I press Submit button with wrong credentials, somtimes it shows an error. But sometimes it shows an error as well, but after couple of seconds it disappears - maybe because of reload page after submit, maybe because of something else.
What can it be? And what can I do with it?
Upd. Problem solved:)