Recent Posts
- (02/24) Calling an Element from a Helper TAGS:CakephpWeb ProgrammingUsageTutorialExample
- (10/14) Forcing A Single Join in CakePHP PaginationTAGS:CakephpCakephp 13DatabaseErrorsHabtmMysqlMssqlWeb ProgrammingUsage
- (08/11) Inserting NOW() into MySQL Using CakePHPTAGS:CakephpDatabaseMysqlMssqlWeb ProgrammingUsage
- (08/07) Best PaginateCount for CakePHP - with Group By SupportTAGS:CakephpBehaviorsWeb ProgrammingUsageDatabaseExampleMysqlHabtmHack
- (04/03) CakePHP Error Messages Not Showing on FormTAGS:CakephpCakephp 13Web ProgrammingErrorsUsage
- (02/06) Sorting Paginated Results Using a Related Model Field in CakePHPTAGS:CakephpWeb ProgrammingUsageExample
- (11/02) Changing CakePHP's Model useTable on the FlyTAGS:CakephpWeb ProgrammingMysqlDatabaseExampleTutorial
- (10/18) The Funniest Error Message Ever - Thank You EclipseTAGS:EclipseWeb ProgrammingErrorsHumorWindowsUsageSoftwarePhpCakephp
Subscribe to my feed
MainelyDesign.com Blog
CakePHP Error Messages Not Showing on Form
Posted on 04/03/2011 at 12:40 pm by Kevin Wentworth
Viewed 3,299 times | 2 comments
I ran into an issue today that I've run into before, except I couldn't remember what I did to fix it (hence this article). I was using CakePHP validation rules to validate a user account details. The CakePHP validation was properly failing (the form data wasn't being saved) and I could tell the validate array was set correctly because the required fields were having the class .required added to them. The only problem? No error messages were being output to the form. The form validation would fail, but the CakePHP error messages were not being shown.
CakePHP Error Messages Not Showing Up?
The fix is simple (stupidly simple). Don't overwrite $this->data AFTER your $this->Model->save() call and/or your $this->Model->validate() call(s). What I was doing was stupid... I was reading the data for the form AFTER trying to save the posted data.
CakePHP Validation Errors Exist Until You Overwrite $this->data
The moral of the story, when you use $this->Model->read(null, $id) to fetch results, $this->data is overwritten, which was the whole problem.
To fix, wrap your $this->Model->read(null, $id) in an if(empty($this->data)) assertion.
Cheers,
-Kevin Wentworth
Tags for CakePHP Error Messages Not Showing on Form
Cakephp | Cakephp 13 | Web Programming | Errors | Usage
Comments for this Posting
Posted by Vishal
on 22/9/11
Thanks man. How did you manage to find this thing?
May be you are super human.
Thanks

Posted by Michael
on 12/4/11
Aaaaaaaaaaaah! thanks! wow, the hours wasted trying to debug this one!
thank you so much :)