Validation: no error message on form


#1

Hi there,

on my login form is no validataion error message shown but the validation works.

How can I show the message in my form?

Thank you!
Ole

UsersController:
public function login()
{
if($this->Auth->User()) {
$this->Flash->error((‘You are already logged in.’));
$this->redirect([‘action’=>’/…/’]);
}
if ($this->request->is(‘post’) and ($this->request->getData(‘loginform’) == ‘1’) ) {
$user = $this->Auth->identify();
if($user === false){
$this->Flash->error(‘Your username or password is incorrect.’);
}else{
if ($user[‘confirmed’] != true) {
$this->Flash->error(‘Your account is not confirmed. Please confirm your Account first.’);
} else {
$this->Auth->setUser($user);
if ($user[‘generated_password’] == 1) {
$this->Flash->success(
(‘Please change your password.’));
$this->redirect([‘action’ => ‘edit’]);
} elseif($this->Auth->redirectUrl()===’/’) {
return $this->redirect([‘controller’ => ‘Pages’, ‘action’ => ‘home1’]);
}else{
return $this->redirect($this->Auth->redirectUrl());
}
}
}
}
}

UsersTabel:

public function validationDefault(Validator $validator)
{

    $validator
        ->email('email')
        ->requirePresence('email', 'create')
        ->notEmpty('email');

    $validator
        ->add('password', [
            'match' => [
                'rule' => ['compareWith', 'repeat_password'],
                'message'=>'The passwords does not match!',
            ]
        ])
        ->add('password', [
            'length'=>[
                'rule'=> ['minLength', 8],
                'message'=> 'The password have to be at least 8 characters!',
            ]
        ])

        ->notEmpty('password')
        ->scalar('password')
        ->maxLength('password', 255)
        ->requirePresence('password', 'create')
        ->notEmpty('password');

    return $validator;
}`

Loginform:
<?= $this->Form->create('Users') ?>
<?= $this->Form->hidden('loginform' , ['value' => '1']) ?>
<?= $this->Form->control('email' , ['class' => 'form-control login-form', 'placeholder' => __('Email adress'), 'label' => false]) ?>
<?= $this->Form->control('password', ['class' => 'form-control', 'placeholder' => __('Password') , 'label' => false]) ?>
<?= $this->Form->button(__('Login'), ['class' => 'primary-btn left']) ?>
<?= $this->Form->end() ?>