how to set readonly property in zend form add element
Asked Answered
C

3

5

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

Chisholm answered 5/6, 2013 at 6:23 Comment(0)
B
6

Try something like this:

$this->addElement('text','text_field',array('attribs' => array('readonly' => 'true'))); 
Bartizan answered 5/6, 2013 at 6:27 Comment(1)
does the same thing work for radio, in my code it seems like it doesntBurgoyne
C
8

Try this

$this->getElement('text')->setAttrib('readonly', 'readonly');
Connivance answered 5/6, 2013 at 6:27 Comment(0)
B
6

Try something like this:

$this->addElement('text','text_field',array('attribs' => array('readonly' => 'true'))); 
Bartizan answered 5/6, 2013 at 6:27 Comment(1)
does the same thing work for radio, in my code it seems like it doesntBurgoyne
H
3

In ZF2 you can create a form by extending Zend\Form and then add form element in the constructor. there you can set the attributes as follows.

use Zend\Form\Form;

class MyForm extends Form {
    public function __construct() {

        $this->add(array(
            'name' => 'name',
            'type' => 'Text',
            'attributes' => array(
                'id' => 'name',
                'class' => 'form-control',
                'readonly' => TRUE,
            ),
            'options' => array(
                'label' => 'Name : '
            )
        ));
     }
}
Haws answered 11/11, 2013 at 4:49 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.