A small update of the advanced validation approach

Published on and tagged with cakephp  validation

If you are using the advanced validation approach together with a CakePHP version higher than, you have to add the following code block to the beginning of the invalidFields() function in your AppModel:

    return false;

Without that update, your beforeValidate() callback functions are no longer called.

3 comments baked

  • Reen

    It’s better to add it after the $this->set($data); so that beforeValidate can access the data.

  • Brandon Pearce

    Hello, sorry to clutter up your blog with this, but I couldn’t find your email address.

    I found a (possible) small bug in the validator. If my field name contains the string ‘password’, it doesn’t seem to validate it, or give an error message if incorrect. (using VALID_NOT_EMPTY). Was this intentional?
    I change the field name in my database from hashed_password to hashed_pwd and it works fine. The verify_password field doesn’t work either, unless I rename it. Very odd.

    Is this something I’m doing wrong or a bug? Any ideas?

  • cakebaker

    @Brandon Pearce: You find my email address on the about page: http://cakebaker.wordpress.com/about/

    Hm, that sounds strange. I think it is not a bug in the validation code, at least, I could not reproduce it here (with the trunk version of CakePHP). But I have no idea what could cause that problem…

© daniel hofstetter. Licensed under a Creative Commons License