显示从Zend_form恢复组合框的内容

时间:2012-04-17 21:17:25

标签: php zend-framework combobox zend-form

我有一个带有组合框的表单

  /*Business user type*/
            $Busertype = new Zend_Form_Element_Select("Busertype");
        $Busertype ->setLabel('Business user type')
          ->addFilter('StripTags') //StripTags : Enlève les caractères HTML
              ->setRequired(true)
               -> setMultiOptions(array(
                                '0' => '-Select your business type-',
                    '1' => 'Owner',
                                    '2' => 'Suplier',
                                    '3' => 'Representative',
                                    '4' => 'Shop'
        ));

我想检索组合框的内容,但是当我echo($busername)时,我会检索组合框的值。那么如何才能显示组合框的内容

部分行动

  $form = new Application_Form_Inscriptionbu(); 
     $this->view->form = $form; //nous assignons le formulaire à la vue pour affichagee
     if ($this->getRequest()->isPost()) {  //Le formulaire est-il posté ?
     $formData = $this->getRequest()->getPost(); // récupère les infos des formulaires

     if ($form->isValid($formData)) { //Si le formulaire passe la validation
        $v = $form->getValues();
        $busername =$v['Busername'];
        echo($busername);
    }

1 个答案:

答案 0 :(得分:0)

如果您想重新显示所选选项中的文字,可以使用getMultiOption

if ($form->isValid($formData)) { //Si le formulaire passe la validation
    $v         = $form->getValues();
    $busername = $v['Busername'];

    echo "You selected $busername which is called " . 
         $form->getElement('Busername')->getMultiOption($busername) . 
         '<br />';
}