2013-06-05 25 views
5

Ciao Sono nuovo in zend framework. Voglio impostare la proprietà ready only nella casella di input in forma zend. esempio come facciamo in htmlcome impostare proprietà readonly in forma zend aggiungi elemento

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

questo è il mio codice di Zend:

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

      ), 

aiuto mee

risposta

5

provare qualcosa di simile:

$this->addElement('text','text_field',array('attribs' => array('readonly' => 'true'))); 
+1

fa la stessa cosa per la radio, nel mio codice sembra non funzionare – almaruf

7

Prova questa

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

In ZF2 è possibile creare un modulo estendendo Zend \ Form e quindi aggiungere l'elemento modulo nel costruttore. lì puoi impostare gli attributi come segue.

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 : ' 
      ) 
     )); 
    } 
}