cake_1.2.6

I'm thoroughly confused by what's happening (or not happening) with my
validation. For one thing, save() does not appear to be calling
validate(). Even when I pass true as the 2nd param, validation does
not occur.

Secondly, the validation, when called explicitly, seems to be wrong.

User model:

public $validate = array(
        'name' => array (
                'username' => array(
                        'rule' => array('minLength', '1'),
                        'required' => true,
                        'message' => 'Please choose a username'
                ),
                'unique' => array(
                        'rule' => array('isUnique'),
                        'on' => 'add',
                        'required' => true,
                        'message' => 'This username is already registered'
                )
        ),
        'email' => array (
                'email' => array(
                        'rule' => 'email',
                        'required' => true,
                        'message' => 'A valid email address is required'
                ),
                'unique' => array(
                        'rule' => array('isUnique'),
                        'on' => 'add',
                        'required' => true,
                        'message' => 'This email address is already registered'
                )
        ),
);

UsersController:

if ($this->User->save($this->data, true))
{
    ....
}

The form inputs are a unique, valid name and a non-unique, valid email
address.

Cake ignores validation and tries to save the data, leading to a DB
error (because of a unique key). When called like this:

if ($this->User->validates($this->data))
{
        if ($this->User->save($this->data, true))
        {

... the save does not proceed. But FormHelper display the wrong
messages:

"Please choose a username"
"A valid email address is required"

I expect to see just one error msg: "This email address is already
registered".

So, first off, has Cake change something with save() recently? Looking
at the source, I can plainly see where it calls validate(). Why do I
need to explicitly call it?

And why are the messages wrong?

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en

Reply via email to