Forms 如何从表单中使用Zend Framework进行选择?

Forms 如何从表单中使用Zend Framework进行选择?,forms,zend-framework,select,frameworks,Forms,Zend Framework,Select,Frameworks,我试着用zend制作一个表单,我知道如何从表单中进行选择 public function init() { $this->addElement("text","titulo",array( "label" => "Titulo" )); $this->setAttrib("id", "enviarNoticia"); $this->setAttrib("clas

我试着用zend制作一个表单,我知道如何从表单中进行选择

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,
                      ));
}

如何添加选项和所选项目?

您应该从控制器中的模型/数据库获取数据,并从控制器向表单分配值,而不是尝试从表单本身获取数据

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

我不太明白问题出在哪里,你想实现什么。你能提供进一步的信息并扩展你的描述吗?