tags:

views:

33

answers:

1

I have a few custom form validation rules I wish to apply. Things like ensuring the password has one capital letter, at least one number, and a symbol.

Where would be best to implement these custom validation rules?

I am currently validating them in a controller, but obviously that won't scale very well when I expand. So I was going to implement them as view helpers.

I don't have too much experience with zend_form. Is there a way to set a custom validation handler when constructing the form object?

Thanks!

+1  A: 

I don't have too much experience with zend_form. Is there a way to set a custom validation handler when constructing the form object?

Yes when constructing the form you can add a set of validators to any form field you wish. I like to make individual Fomr classes that extend Zend_Form... and here i set the default configuration for that form. If something need to be different in a specific usage then i override as necessary in the controller.

Check out the manual and update your question or start a new one ith specific issues you run in to.

prodigitalson
Thanks! I am also new to stackoverflow. I see this is less like a forum for stupid questions.Was just reading the manual then. Will update my question with something more specific should I have further trouble.
Zenph
It's also possible (and often advisable) to push your validation (via Zend_Form) down into your model layer: http://weierophinney.net/matthew/archives/200-Using-Zend_Form-in-Your-Models.html
timdev
The only problem with that is what if I want to set custom validation errors and I don't use zend_form to do so. Suddenly, I am defining these error messages within a model, which to me, does not seem like it belongs there.
Zenph
you would simply add method to change the validation messages on the form instance via accessors on the form and/or model - granted ive never don this with ZF as anything that would denote a need for theis level of complexity i would be using Symfony for instead of ZF. That said Symfony uses a similar validation system to what Matthews post suggest - its just more robust and more tightly coupled.
prodigitalson