-- Ralf Eggert <[email protected]> wrote
(on Sunday, 26 August 2012, 02:39 PM +0200):
> I have a single form for users, which is both used for registration and
> update. When a user is registered, I instantiate the form and clear the
> elements 'status' and 'group' which I only need for updates. So far so good.
>
> Now I have an input filter class as well. I want to have one both for
> registration and updates like the form. For registration I set the
> 'status' and 'group' to not required, for updates I set the 'password'
> to not required. Not I have the problem with the email adress which
> should be unique. For registration I use the Db\NoRecordExists
> validator, for updates I need to exclude the current email on the fly.
>
> Does anyone think it is bad practice to use the same form and input
> filter for different purposes? Should I rather create one form and one
> input filter for each purpose and risk some code duplication?
No -- I think it makes sense to keep the information together.
One note, though: you don't need to necessarily remove validators, or
change from required to not required -- instead, set a validation group
on the form; that way it will only try and validate those listed, and
will only bind the values for those in the group. The usage is quite
simple:
$form->setValidationGroup($key1, $key2, $key3, $etc);
// or:
$form->setValidationGroup(array('key1', 'key2', 'key3', 'etc'));
--
Matthew Weier O'Phinney
Project Lead | [email protected]
Zend Framework | http://framework.zend.com/
PGP key: http://framework.zend.com/zf-matthew-pgp-key.asc
--
List: [email protected]
Info: http://framework.zend.com/archives
Unsubscribe: [email protected]