When disabling an element or option in a Zend_Form we use the function setAttrib() or, if multiple options, setAttribs(). These examples are made in Zend Framework 1.10
Disable a form element in the controller
$form = new Application_Form_MyForm(); $form->getElement('elementName')->setAttrib('disable', 'disable');
This will disable the whole ‘elementName’ element.
Disable option in a radio or select element
In declaration of element:
class Application_Form_MyForm extends Zend_Form { ... $typeOfLap = new Zend_Form_Element_Radio('elementName'); $typeOfLap->setRequired(true) ->addMultiOptions(array( 'A' => 'Option A', 'B' => 'Option B')); ... }
In controller
$form = new Application_Form_MyForm(); $form->getElement('elementName')->setAttrib('disable', array('A'));
This will disable option ‘Option A’. If you want to also disable ‘Option B’ you can add it to the disable array: array(‘A’, ‘B’). It works the same way with select elements
Awesome, thanks for the detailed explanation! I was struggling to find any documentation on this so thank you for sharing 😆