A small update of the advanced validation approach

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

if(!$this->beforeValidate())
{
    return false;
}

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

3 Comments

  1. Posted May 10, 2006 at 11:55 am | Permalink

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

  2. Posted May 10, 2006 at 8:20 pm | Permalink

    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?

  3. Posted May 11, 2006 at 1:06 pm | Permalink

    @Brandon Pearce: You find my email address on the about page: https://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…


%d bloggers like this: