How can I display the validation error messages in the Login view of the UsersController?
Hi, I hope someone can help me. How can I get to show the validation errors when entering wrong data fields of the login form? in add, edit when submitting the form are displayed correctly.
Users/login.ctp

<h1 class="h4 mb-3 font-weight-bold">Acceso administración</h1>
<?= $this->Form->create() ?>
<fieldset>
<?= $this->Form->control('username',['class' =>'form-control mb-2','placeholder' => 'Nombre de usuario','label' => false ,'escape' => false]);?>
<?= $this->Form->control('password',['class' =>'form-control mb-2','placeholder' => 'Contraseña','label' => false ,'escape' => false]);?>
<?= $this->Form->button(__('Acceder'),['class' => 'btn btn-lg btn-success w-100 my-3'])?>
<?= $this->Form->end() ?>
</fieldset>
</div>
</div>
UsersTable.php
class UsersTable extends Table
{
public function validationDefault(Validator $validator){
$validator
->requirePresence('username', true)
->notEmptyString('username', 'El nombre de usuario es obligatorio', false)
->add('username', [
'unique' => [
'rule' => 'validateUnique',
'provider' => 'table',
'message' => 'El nombre de usuario ya existe'
]
]);
$validator
->allowEmptyString('password', 'La contraseña es obligatoria', false)
->add('password', [
'length' => [
'rule' => ['minLength', 5],
'message' => 'La contraseña debe tener mínimo 5 caracteres',
]
]);
return $validator;
}
Action login in UsersController.php
public function login(){
$this->viewBuilder()->setLayout('publico');
if ($this->request->is('post')) {
$user = $this->Auth->identify();
if ($user) {
$this->Auth->setUser($user);
$this->Flash->success(__('El administrador ha iniciado sesión correctamente'));
return $this->redirect($this->Auth->redirectUrl());
}
$this->Flash->error(__('Nombre de usuario o contraseña incorrectos, inténtalo de nuevo.'));
}
}
Thank you very much and I hope someone can help me