Search code examples
formsvalidationcakephpcakephp-3.0validationerror

CakePHP 3 and form validation errors


I use cakePHP 3 and I have a sign in form with Form->input(). If on purpose I make an error, this error doesn't whow up under the Form field. It doesn't appear anywhere.

My code is like this:

    $newUser = $this->Users->newEntity($this->request->data());

    if (!$this->Users->save($newUser)) {
        debug($newUser->errors());
        $this->Flash->error('Error');
        return;
    }

Debug show the errors, but shouldn't they appear under each form element automatically?


Solution

  • ok I found the error. I wasn't passing in Form->create the entiry but null. I did it like

    $this->Form->create($entity...
    

    and works nicely.