Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to unset elements in zend form

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?

like image 790
Awais Qarni Avatar asked Oct 27 '11 07:10

Awais Qarni


3 Answers

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

Example

$form->removeElement('merchantLogo');
like image 182
Phil Avatar answered Nov 03 '22 16:11

Phil


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

like image 4
Hikaru-Shindo Avatar answered Nov 03 '22 16:11

Hikaru-Shindo


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');
}
like image 3
Alex Pliutau Avatar answered Nov 03 '22 17:11

Alex Pliutau