how to set readonly property in zend form add element

Delta picture Delta · Jun 5, 2013 · Viewed 14.2k times · Source

Hi I am new in zend framework. I want to set ready only property on input box in zend Form. example as we do in html

<input type ="text" readonly="readonly" />  

this is my zend code:

$this->addElement('text', 'name', array(
            'label'      => '',
            'required'   => true,
            'filters'    => array('StringTrim'),
            'style'    => array('width:338px'),
             'autocomplete' => 'off',
            'decorators'=>Array(
            'ViewHelper',
            'Errors',

           ),

help mee

Answer

Kiren Siva picture Kiren Siva · Jun 5, 2013

Try this

$this->getElement('text')->setAttrib('readonly', 'readonly');