Here is what I do :)

Define the validation in the model with a rule name for each
validation you want to apply to a field, as specified in:

http://book.cakephp.org/view/133/Multiple-Rules-per-Field

Example:
'username' => array(
   'users_username_rule' => array( 'rule' => array('custom', '/^[a-z]
{1,}[ a-z0-9]{3,}$/i') ),
   'users_username_length_rule' => array('rule' => array('between',
4,40) )
),


In your view, override the model error messages, as specified in:

http://book.cakephp.org/view/133/Multiple-Rules-per-Field

Example:

print(
   $form->input(
      'username',
       array(
         'label' => __('user name',true),
         'error' => array(
            'users_username_rule' => __('users_username_rule',true),
            'users_username_length_rule' => __
('users_username_length_rule',true)
         )
      )
   )
);

Enjoy,
   John

On Dec 17, 11:24 am, pablosky <pablo00...@hotmail.com> wrote:
> Thanks for answering.
>
> I do this because I need to translate the messages of validation. I
> found this method in the book and also cake "bakers":
>
> http://book.cakephp.org/view/133/Multiple-Rules-per-Field(In the 
> end)http://bakery.cakephp.org/articles/view/multiple-rules-of-validation-...
>
> How else can I translate the custom messages of validation?
>
> Tranks
>
> On 17 dic, 02:07, peterchenadded <peterchenad...@gmail.com> wrote:
>
> > I believe you can only include one default error message using the
> > form helper. It is not possible to include more than one. Which would
> > be the reason the 'unique' message is not showing as it is simply
> > ignored.
>
> > Please see below to get your validation errors working
>
> > In your model:
>
> > var $validate = array(
> >   'username' => array(
> >     'between' => array(
> >       'rule' => array('between', 4, 10),
> >       'message' => 'username must be between 4 and 10',
> >       'last' => true,
> >       'required' => true
> >     ),
> >     'unique' => array(
> >       'rule' => 'isUnique',
> >       'message' => 'username already exists'
> >     )
> >   )
> > );
>
> > In your view:
>
> > <?php echo $form->input('username'); ?>
>
>

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+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en

Reply via email to