2013-06-05 8 views
5

Witam Jestem nowy w frameworku Zend. Chcę ustawić właściwość Ready only w polu wejściowym w formularzu Zend. przykład jak my w htmljak ustawić właściwość readonly w formularzu zend dodaj element

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

to jest mój kod zend:

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

      ), 

help mee

Odpowiedz

5

Spróbuj czegoś takiego:

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

to samo działa dla radia, w moim kodzie wydaje się, że to nie robi – almaruf

7

Spróbuj

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

W ZF2 można utworzyć formularz poprzez rozszerzenie Zend \ Form, a następnie dodać element formularza do konstruktora. tam możesz ustawić atrybuty w następujący sposób.

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 : ' 
      ) 
     )); 
    } 
} 
Powiązane problemy