How to unset elements in zend form

Awais Qarni picture Awais Qarni · Oct 27, 2011 · Viewed 10.5k times · Source

I have a zend form in which I have many elements. I use form on many places. I have an element of file and that is:

$file= new Zend_Form_Element_File('merchantLogo');
        $file->setDestination("application_data/merchant/logo/original/");
        $file->addValidator('Count', false, 1);
        $file->addValidator('Extension', false, 'jpg,png,gif,jpeg');
        $file->setDecorators(array('ViewHelper','Errors'));

Now What I want to ask that how can I unset any element of this zend form. I want this because although on my one action I am not using this element, but this element is creating problem. So how to unset any element?

Answer

Phil picture Phil · Oct 27, 2011

Use Zend_Form::removeElement(). See http://framework.zend.com/manual/en/zend.form.forms.html#zend.form.forms.elements.methods

Example

$form->removeElement('merchantLogo');