Disabling Zend_Form Elements

Written by James Mansson on December 1, 2013 Categories: Zend Framework 1

Sometime we may wish to disable elements on a form. For instance, we may share the same form for adding and editing a record, and a particular field is read only when editing. When working with Zend_Form, we can use the setAttrib function of a form element to perform this task.

Some elements (e.g. text elements) are disabled by making them read only. Assuming the for element is represented by the variable $element, we can do this by:

$element->setAttrib('readonly', 'true');

For other elements (e.g. select elements), we set the disabled attribute to disabled by:

$element->setAttrib('disabled', 'disabled');
No Comments on Disabling Zend_Form Elements

Leave a Reply

Your email address will not be published. Required fields are marked *