2012-02-01 4 views
0

메신저 젠드와 양식을 만들려고, 그리고 난 형태 선택 옵션 항목을 추가하는 방법폼에서 Zend Framework를 사용하여 셀렉션을 수행하는 방법은 무엇입니까?

public function init() 
{ 
    $this->addElement("text","titulo",array(
         "label" => "Titulo" 
        )); 
    $this->setAttrib("id", "enviarNoticia"); 
    $this->setAttrib("class", "FormEnviarNoticia"); 
    $this->setMethod("post"); 
    $this->addElement("textarea","noticia",array()); 
    $this->addElement("submit","Enviar",array()); 
    $this->addElement("multiselect", "categories",array(
         "label"  => "Categories", 
         "required" => false, 
        )); 
} 

에서 선택을 수행하는 방법을 알 수 있습니까?

+0

나는 무엇이 문제이고 달성하기를 원하는지 정확히 이해하지 못합니다. 추가 정보를 제공하고 설명을 넓혀 주시겠습니까? –

답변

1

양식 자체에서 데이터를 가져 오는 대신 컨트롤러의 모델/데이터베이스에서 데이터를 가져 와서 컨트롤러의 양식에 값을 할당해야합니다.

// In a controller 

// get the options from your model or database into an array 
$options = array('name' => 'value', 'name2' => 'value2', 'name3' => 'value3'); 

$form = new Application_Form_Form(); 
$form->getElement('categories')->setMultiOptions($options); // set the $options as the options for the categories multiselect 

if ($this->getRequest()->isPost()) { 
    if ($this->form->isValid($this->getRequest()->getPost())) { 
     // form passed validation 
    } 
} else { // form was not submitted 
    // to set default value(s) for the select 
    $form->getElement('categories')->setValue(array('name2', 'name3')); 
} 
관련 문제