Hello Benjamin, this should work:

'password' => array(
        'notNull' => array(
                'rule' => array('custom', VALID_NOT_EMPTY),
                'required' => true,
                'message' => 'Please enter a password.'
        ),

        'between' => array(
                'rule' => array('between', 4, 12),
                'message' => 'Please check the number of characters in your
password.'
)

allowEmpty defaults to false so u don't need to specify it unless u
want to change it. I think allowEmpty and required options are checked
before the rule specification. So if allowEmpty is false and u submit
no data, cake won't check the rule because validation will return
false anyway.

When you are using multiple validation rules per field, cake will
check all of those rules. That means, in your case, if your first rule
fails, your second rule will fail too and u'll get 'between' rule
error msg even when the password was empty. If you want to change this
behaviour you can simply add 'last'=>true option to desired rules,
which will force cake to stop further validation for certain field if
one of them invalidates.

Cheers.

On 3. Feb, 11:06 h., cisbrh <[EMAIL PROTECTED]> wrote:
> Hi everybody,
> first of all thank you for the really good work you've doing on cake.
> I've used it 2 years ago for a massive application and I had to write
> my own postgresql layer... The work done since then especially on 1.2
> is amazing.
> Anyway. I am trying to use multiple validation rules (1.2) with
> allowEmpty and required but I just can't get it working.
> I've look at the sources and it looks like the 2 keys must be included
> in their own rule declaration ie:
> 'password' => array(
>                         'notNull' =>array(
>                                 'allowEmpty' => false,
>                                 'required' => true,
>                                 'message' => 'Please enter a password.'
>                         ),
>                         'between' => array(
>                                 'rule' => array('between', 4, 12),
>                                 'message' => 'Please check the number of 
> characters in your
> password.'
>                         ).....
>
> But that does not work because model will default the keywords value
> for 'rule' to 'blank' !!! So what value should I give to 'rule'.
> If I put allowEmpty and required outside a rule declaration it breaks
> completely ie:
> 'password' => array(
>                         'allowEmpty' => false,
>                         'required' => true,
>                         'message' => 'Please enter a password.',
>                         'between' => array(
>                                 'rule' => array('between', 4, 12),
>                                 'message' => 'Please check the number of 
> characters in your
> password.'
>                         ).....
>
> so I am a bit stuck.
> I guess I could use a custom rule which always return true and let
> required and allowEmpty to invalidate if needed but surely there is a
> better way ?
> Thanks in advance.
> Benjamin
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" 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