Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 473
Harris Avatar asked Jun 18 '26 10:06

Harris


1 Answers

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.

like image 97
Harris Avatar answered Jun 21 '26 03:06

Harris



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!