Tuesday, February 23, 2010

Re: How do I add custom validation in controller?

Do it in a model (not controller) - cake flow:

var $validate = array(
'accept_terms' => array(
'notEmpty' => array(
'rule' => array('comparison', '!=', 0),
'required' => true,
'message' => 'Musisz zaakceptować regulamin',
'on' => 'create',
),
),
);

ps.: (there is no accept_terms in my database table of course.

and add to it custom validation rules (links in WebbedIT post)

On Feb 23, 11:35 am, Zac Tolley <zac.tol...@gmail.com> wrote:
> I have created a form with the html and form helpers and setup
> validation rules in my model and this seems to work pretty well
> (anyone got this integrated with jquery?)
>
> I have a question though, in my form I have a couple of extra fields,
> one is a checkbox to accept terms and conditions, and another is a
> password validation field (they type in new password twice).
>
> Now, I can easily put some logic into the controller to check these
> things when the form is submitted, but is there any way I can do this
> in such a way that it fits into the cake flow, so if one of my checks
> fails it go back to the form and puts up a messing below the filed in
> the same style, or am I going to do this manually?

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

No comments: