Monday, September 15, 2008

Re: Why is the Validation Filters Array Processed Backwards and Returns Conservatively?

Actually, it runs them in "reading order" but doesn't stop when
there's an error, so the latest error message overrides the earlier
ones.

You can force the validation to stop when a specific rule fails by
including the 'last' => true parameter in the rule definition.

hth
grigri

On Sep 15, 2:26 pm, RichardAtHome <richardath...@gmail.com> wrote:
> Actually, I don't think it does!
>
> I was always under the impression it (CakePHP 1.2) runs through the
> $validate array in it's natural order and falls out at the first fail.
>
> ie.
>
> var $validate = array(
>   "name"=>array(
>     "required"=>array(
>       "rule"=>array("minLength, 1),
>       "message"=>"is required",
>       "required"=>true
>     ),
>     "unique"=>array(
>       "rule"=>"isUnique",
>       "message"=>"must be unique"
>     )
>   )
> );
>
> The unique rule won't be tested if the required rule fails.
>
> This is certainly my experiance (of CakePHP 1.2).
>
> On Sep 13, 8:32 am, "O.J. Tibi" <ojt...@gmail.com> wrote:
>
> > Hi guys,
>
> > Just wondering why is the validation filters array ($validate)
> > processed backwards and when a validation criteria matched, returns
> > conservatively? I asked this question because it's quite inconvenient,
> > if not unconventional, that we write the filters in reading order, and
> > we expect that the first match upon validating our form $data is from
> > the top of our $validate array.
>
> > Thanks in advance!
--~--~---------~--~----~------------~-------~--~----~
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: