Monday, February 22, 2010

Re: validation strangeness

I am not sure if it's the same problem i've got, but my issue was due
to not respecting naming convention. I missed model naming at plural.
Once I got everything to the single, it worked.

Hope it helped!

On Feb 4, 1:19 am, cricket <zijn.digi...@gmail.com> wrote:
> cake_1.2.6
>
> I'm thoroughly confused by what's happening (or not happening) with myvalidation. For one thing, save() does not appear to be calling
> validate(). Even when I pass true as the 2nd param,validationdoes
> not occur.
>
> Secondly, thevalidation, 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.
>
> Cakeignoresvalidationand 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+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en

No comments: