On Sat, Jun 25, 2011 at 4:29 PM, David Mintz <[email protected]> wrote: > On Sat, Jun 25, 2011 at 10:39 AM, Jurian Sluiman <[email protected] >> wrote: > >> On Friday 24 Jun 2011 16:30:18 David Mintz wrote: >> > On Thu, Jun 23, 2011 at 3:31 PM, James Ganong <[email protected] >> >wrote: >> > Don't know if this is considered the best of practices, but sometimes in >> my >> > Zend_Form's init(), I examine the request parameters by going >> > Zend_Controller_Front::getInstance()->getRequest() and apply validation >> > logic depending on who they are and what they are trying to do. >> > >> > In your case it seems like you could add as many elements (and their >> > validators and filters) as you need and no more by doing something like >> > that. >> >> I'd rather override Zend_Form::isValid() in that case where for example, >> based >> on a checkbox a set of form elements becomes required: >> >> class MyForm extends Zend_Form >> { >> public function isValid($data) >> { >> if (isset($data['shipping']) && (bool) $data['shipping'] === true) { >> $this->getElement('shipping-address')->setRequired(); >> } >> return parent::isValid($data); >> } >> } >> >> Then you keep you logic within the validation steps and not affecting the >> form >> instantiation. >> >> > I like that. But how about the scenario where you're creating 1 or more > elements client-side that did not exist when the form was first displayed. > Let's say it's a family membership form for a zoo and the parent's contact > data is required, but you want first name, last name, age for zero or more > children, and your form/javascript allows them to add new elements as > needed. What's the best practice for that? > > -- > David Mintz > http://davidmintz.org/ > It ain't over: > http://www.healthcare-now.org/ >
I have an idea on how to deal with this. Since a form can be configured by a Zend_Config. There's nothing that says you can't clone the config, change it to suit your needs and feed it to the class when you instantiate it. The only problem is I don't know the key to configure display groups through a Zend_Config. Jamie -- List: [email protected] Info: http://framework.zend.com/archives Unsubscribe: [email protected]
