On Mon, Nov 19, 2012 at 10:33 AM, MrNorm <oli...@oli.me> wrote:
> I'm a little new to ZF2 so please forgive me if the question is
> mind-numbingly obvious.
>
> I have an entity called 'User', which has a number of fields and and input
> filters, created through a 'getInputFilter' function.
>
> I'm trying to work out in my head what the best solution for my application
> would be. I would like to use some of the elements (e.g. email and password)
> in a login form, but then all of them in a 'edit account' form. The benefit
> to me doing it that way is that all of my validators and filters are in one
> place, in the entity.

Use validation groups. :)

    $form->setValidationGroup('email', 'password'); // validate only
email and password

This was precisely the sort of use case that feature was designed for.

(The feature is also available on the InputFilter -- in fact, Form
proxies that call to the composed InputFilter.)

> What I've done previously is put a 'type' condition on the getInputFilter
> function, so only some elements will be added to the input filter, depending
> on what 'type' is from the controller. That way, if 'type' is 'login', then
> only 'email' and 'password' will be added to the input validator. That means
> when I include two elements with the same name on a form, then the form will
> validate and filter correctly when running setInputFilter against the form.
>
> I'm convinced this isn't the right way. Could someone help me in the best
> way to approach this?


-- 
Matthew Weier O'Phinney
Project Lead            | matt...@zend.com
Zend Framework          | http://framework.zend.com/
PGP key: http://framework.zend.com/zf-matthew-pgp-key.asc

-- 
List: fw-general@lists.zend.com
Info: http://framework.zend.com/archives
Unsubscribe: fw-general-unsubscr...@lists.zend.com


Reply via email to