Hey!

The rules are indeed executed in order, but only the last validation
rule that didn't pass will be shown. If you want Cake to stop
validating if a condition isn't met, you can set 'last' => true

Here the second rule will only be executed if the first rule passes:

var $validate = array(
                 'word' => array(
                         array(
                                 'required'      => true,
                                 'allowEmpty'=> false,
                                 'rule'          => '/\S+/',
                                 'message'       => 'Required field.',
                                 'last' => true
                         ),
                         array(
                                 'rule'          => array('minLength',
3),
                                 'message'       => '3 caracters min.'
                         ),
                 )
         );



On 6 heinä, 19:44, Dia <[EMAIL PROTECTED]> wrote:
> Hi
>
> I noticed a strange behaviour and wanted to know if it's there's a
> order on executing validation rules
>
> the example :
>
> case 1 :
>         var $validate = array(
>                 'word' => array(
>                         array(
>                                 'required'      => true,
>                                 'allowEmpty'=> false,
>                                 'rule'          => '/\S+/',
>                                 'message'       => 'Required field.'
>                         ),
>                         array(
>                                 'rule'          => array('minLength', 3),
>                                 'message'       => '3 caracters min.'
>                         ),
>                 )
>         );
>
> case 2 :
>         var $validate = array(
>                 'word' => array(
>                         array(
>                                 'rule'          => array('minLength', 3),
>                                 'message'       => '3 caracters min.'
>                         ),
>                         array(
>                                 'required'      => true,
>                                 'allowEmpty'=> false,
>                                 'rule'          => '/\S+/',
>                                 'message'       => 'Required field.'
>                         ),
>                 )
>         );
>
> submitting an empty field will display '3 caracters min.' in case 1
> and will display 'Required field.' in case 2...
> for me it's a strange behaviour, I would think that rules are executed
> in the order they are declared...
>
> so how is determined the execution order ?
>
> 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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to