CakePHP: Keep validation data upon redirect

我怕爱的太早我们不能终老 提交于 2019-12-23 06:04:05

问题


I have seen this problem mentioned a lot here, but I couldn't find any satisfactory answer, so I'll try to formulate it a bit differently:

I have a login form and a registration form for users on the same page (let's call it the "frontpage").

Each form leads to a different controller action. Upon validation, cakephp is trying to display the validation errors in the users/login and users/register Views, but I don't have and I don't want those Views, so I'm forced to do a redirect back to my "frontpage". However, upon redirecting, the validation data is lost.

How do I go about keeping the validation data to be displayed on my frontpage, without having to add separate pages for the login and register functions?


回答1:


Cakephp keeps its validation errors in

$this->ModelName->invalidFields();

If you want it to behave persisten the i believe you will have to keep it in a session variable. i.e if your redirects are loosing the property value then try keeping it in a session variable.

Update:

invalidFields executes the whole validation process again and $this->ModelName->validationErrors should be used instead.



来源:https://stackoverflow.com/questions/12553192/cakephp-keep-validation-data-upon-redirect

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