Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to disable a form element in a Zend Form?

Tags:

I want to display a Zend Form with one of the elements shown as disabled. I'm setting the value so the user can see it, but I want to disable it so the user can't edit it. This may also involve some sort of css/javascript to ensure that it looks like, and is not editable by the user. This is my element:

    $this->addElement('text', 'username', array(         'label'      => 'Username:',         'required'   => true,         'filters'    => array('StringTrim'),         'validators' => array(             array('StringLength', false, array(2, 50))         )     )); 
like image 971
Andrew Avatar asked Nov 18 '09 20:11

Andrew


1 Answers

You should be able to use:

$this->username->setAttrib('disabled', 'disabled'); 

I think you can as well:

$this->addElement('text', 'username', array(     'label'      => 'Username:',     'required'   => true,     'filters'    => array('StringTrim'),     'validators' => array(         array('StringLength', false, array(2, 50))     ),     'attribs'    => array('disabled' => 'disabled') )); 
like image 194
smack0007 Avatar answered Sep 28 '22 06:09

smack0007