How to unset elements in zend form
Asked Answered
P

4

8

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?

Pyelonephritis answered 27/10, 2011 at 7:58 Comment(0)
B
12

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

Example

$form->removeElement('merchantLogo');
Bloxberg answered 27/10, 2011 at 8:2 Comment(0)
B
4

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

Bedard answered 27/10, 2011 at 8:4 Comment(0)
I
3

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');
}
Itin answered 27/10, 2011 at 8:3 Comment(0)
C
0

$form = $form->remove('merchantLogo'); // or chain to remove ->('anotherElement');

Newbie note:

Replace $form with the return value of remove(') method to use the updated form.

Crier answered 23/1, 2019 at 7:54 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.