Set attribute on select option with Zend_Form

Today I needed to disable a few options in a status select box when building a Zend Framework application.
Luckily this is very easy to do, but you just have to know how.

Make sure you set all available options first:

$element->setMultiOptions($options);

Below that line you can set an attribute on some options. For example, if you want to disable the first, second, and fith option in the select box:

$element->setAttrib('disable', array(1, 2, 5));

And you’re done!

Tags: ,,