Home > cakePHP > Using validates() in cakePHP 1.2

Using validates() in cakePHP 1.2

December 4th, 2008

Today I was dealing with a nasty problem. I was trying to validate form data without saving it, which was supposed to work like this:


if ($this->Location->validates($this->data)) {}

The only problem was… it didn’t work! It took me some time until I figured out that the Parameter usage of validated() is deprecated: Thanks to cakebaker for his blog entry!

So if you are trying to achieve the functionality from above you should use this code instead:


if ($this->Location->create($this->data) && $this->Location->validates()) {}

cakePHP

  1. December 5th, 2008 at 08:00 | #1

    Well, the parameter usage has been undeprecated in the meantime, but the parameter has now a new meaning, see my more recent article: http://cakebaker.42dh.com/2008/11/05/the-modelvalidates-trap/

  2. December 5th, 2008 at 08:10 | #2

    Daniel, thanks for pointing this out! BTW: your blog has been *really* helpful to me with several cakePHP issues! Great work!

  1. No trackbacks yet.