CakePHP 3 and form validation errors

醉酒当歌 提交于 2019-12-23 16:08:32

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/32936259/cakephp-3-and-form-validation-errors

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!