Discussion:
Hide a Zend_Form_Element
flow
2009-08-10 15:14:41 UTC
Permalink
Hi,

I want to hide a zend_form_element and I was wondering that there is no
visible-attribute or something like that.
Of course I can give the element a class and hide it via CSS, but is this
the "correct" way?
I think It would be better to hide the element in the init of the form so
that it doesn't get rendered.

Thanks for your help.
--
View this message in context: http://www.nabble.com/Hide-a-Zend_Form_Element-tp24901620p24901620.html
Sent from the Zend Framework mailing list archive at Nabble.com.
Hector Virgen
2009-08-10 16:05:55 UTC
Permalink
Do you need it to be invisible but submitted with the post data? Try making
it a hidden input field:
$this->addElement('hidden', 'myfield', array(/* ... */));

Or you can remove the element completely if you don't need it to be
submitted:

$form = new MyForm();
$form->removeElement('myfield');

Or, like you said, you can use CSS to make them invisible with display:none.

--
Hector
Post by flow
Hi,
I want to hide a zend_form_element and I was wondering that there is no
visible-attribute or something like that.
Of course I can give the element a class and hide it via CSS, but is this
the "correct" way?
I think It would be better to hide the element in the init of the form so
that it doesn't get rendered.
Thanks for your help.
--
http://www.nabble.com/Hide-a-Zend_Form_Element-tp24901620p24901620.html
Sent from the Zend Framework mailing list archive at Nabble.com.
flow
2009-08-10 16:24:15 UTC
Permalink
Hello Hector,

thanks for your reply.
removeElement is the way to go.
Post by Hector Virgen
Do you need it to be invisible but submitted with the post data? Try making
$this->addElement('hidden', 'myfield', array(/* ... */));
Or you can remove the element completely if you don't need it to be
$form = new MyForm();
$form->removeElement('myfield');
Or, like you said, you can use CSS to make them invisible with
display:none.
--
Hector
Post by flow
Hi,
I want to hide a zend_form_element and I was wondering that there is no
visible-attribute or something like that.
Of course I can give the element a class and hide it via CSS, but is this
the "correct" way?
I think It would be better to hide the element in the init of the form so
that it doesn't get rendered.
Thanks for your help.
--
http://www.nabble.com/Hide-a-Zend_Form_Element-tp24901620p24901620.html
Sent from the Zend Framework mailing list archive at Nabble.com.
--
View this message in context: http://www.nabble.com/Hide-a-Zend_Form_Element-tp24901620p24902809.html
Sent from the Zend Framework mailing list archive at Nabble.com.
Continue reading on narkive:
Loading...