Thanks, you are right, I didn't sorted my rules in the proper order.

I had to sort 'username' rules that way:

'username'      => array(
                        'unique'        => array(
                                'rule'          => array('checkUnique', 
'username'),
                                'message'       => 'This name is already taken',
                        ),
                        'alphanumeric'  => array(
                                'rule'          => 'alphanumeric',
                                'message'       => 'Only alphanumeric allowed',
                        ),
                        'required'      => array(
                                'rule'                  => VALID_NOT_EMPTY,
                                'message'               => 'This field cannot 
be empty',
                        )

If empty the last message is displayed, if incorrect characters are
found the second, and then it checks if the username is unique. Now it
works fine.
Hope that'll help other.


On 28 jan, 21:55, MonkeyGirl <[EMAIL PROTECTED]> wrote:
> I'm no expert, but this might help:
>
> CakePHP's model validation treats later rules with a higher priority
> than earlier ones. This means that if neither rule is matched, it's
> the last rule's message that will show. I'm not sure why it works this
> way, but that's what seems to happen.
>
> So for example, a blank name might trigger the "it's empty" rule as
> well as the "this name's already taken" rule if you already put in a
> blank name while testing the form earlier on, and the last of those
> rules is the one you'd see the message for.
>
> Most of what the thread you linked to was about seemed to be moving
> messages into the view. The way this works is that you name your rules
> in the model, and if any given rule is the reason the data couldn't
> save, that rule name is passed to the view so it can print out the
> specific error message for that rule.
>
> The model's validation has this kind of syntax:
>
> var $validate = array(
>   'fieldElement' => array(
>     'madeUpRuleName' => array(
>       'rule' => 'ruleFunction'
>     ),
>     'anotherRuleName' => array(
>       'rule' => 'otherRuleFunction'
>     )
>   )
> )
>
> So ruleFunction and otherRuleFunction would be the names of the rules
> to apply, such as alphaNumeric, between, or any method you create in
> that model or app_model that returns TRUE when it's happy.
>
> madeUpRuleName and anotherRuleName, on the other hand, are arbitrary
> names you can make up for the rules. Their purpose is to get passed on
> to the view, so you can give them error messages like this:
>
> echo $form->input('fieldElement', array(
>   'label' => 'Fancy name',
>   'error' => array(
>     'madeUpRuleName' => 'You also did not do this right',
>     'anotherRuleName' => 'You did not do this right'
>   )
> ));
>
> Note that if neither rule is met, anotherRuleName will be the one to
> give an error message because it appears lower on in the model. (The
> order in the view doesn't seem to matter.)
>
> I hope I got this right... I suspect someone might correct me now. :)
>
> Hope that helps,
> Zoe.

--~--~---------~--~----~------------~-------~--~----~
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