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.

Regards, Jurian
-- 
Jurian Sluiman
Soflomo - http://soflomo.com

-- 
List: [email protected]
Info: http://framework.zend.com/archives
Unsubscribe: [email protected]


Reply via email to