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?
Use Zend_Form::removeElement()
. See http://framework.zend.com/manual/en/zend.form.forms.html#zend.form.forms.elements.methods
Example
$form->removeElement('merchantLogo');
This is quiete easy:
$this->removeElement('merchantLogo');
The public function removeElement() on the Zend_Form takes the name of an element and removes it from the form.
See: http://framework.zend.com/manual/en/zend.form.forms.html#zend.form.forms.elements.methods
1:
$element = new Zend_Form_Element_Text('test');
if ($condition) {
$form->addElement($element);
}
2:
$element = new Zend_Form_Element_Text('test');
$form->addElement($element);
if (!$condition) {
$form->removeElement('test');
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With