只是想知道它是如何工作的以及如何处理信息.
假设我有一个这样的表格:
$multi = new Zend_Form_Element_Multiselect('users'); $multi->setMultiOptions(array( //'option value' => 'option label' '21' => 'John Doe','22' => 'Joe Schmoe','23' => 'Foobar Bazbat' )); $form->addElement($multi);
如果用户从多选框中选择一个或多个值…
使用像这样的多选元素:
$multi = new Zend_Form_Element_Multiselect('users'); $multi->setMultiOptions(array( //'option value' => 'option label' '21' => 'John Doe','23' => 'Foobar Bazbat' )); $form->addElement($multi);
您可以像这样获取元素的值:
public function indexAction() { $form = new MyForm(); $request = $this->getRequest(); if ($request->isPost()) { if ($form->isValid($request->getPost())) { $values = $form->getValues(); $users = $values['users']; //'users' is the element name var_dump $users; } } $this->view->form = $form; }
$users将包含已选择的值的数组:
array( 0 => '21',1 => '23' )