views:

449

answers:

1

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))
        )
    ));
+2  A: 

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')
));
smack0007
cool thanks. just what i needed.
Andrew