【问题标题】:how to define multi select element in zend framework2?如何在zend framework2中定义多选元素?
【发布时间】:2013-04-27 11:24:41
【问题描述】:

我需要在表单中显示多选元素。我用这个:

        $this->add(array(
        'type' => 'Zend\Form\Element\Select',
        'name' => 'services',
        'attributes' =>  array(
            'id' => 'state',
            'multiple'=>true,
            'options' => array(
                'Web Design'=>'Web Design',                    
                'Web Software'=>'Web Software',
                'IT Solutions'=>'IT Solutions',
                'SEO'=>'SEO',                    
            ),
        ),
        'options' => array(
            'label' => 'Services',
        ),
    ));

并在我的模型中定义验证器:

            $inputFilter->add($factory->createInput(array(
            'name'     => 'services',
            'required' => false,
            'validators' => array(
                array(
                    'name'    => 'NotEmpty',
                ),
            ),
        )));

但是当我在控制器中使用 $form->isValid() 验证表单时,它返回 false。 我该怎么办?

【问题讨论】:

    标签: forms validation zend-framework2 multi-select


    【解决方案1】:

    试试看

        $inputFilter->add($factory->createInput(array(
            'name' => 'services',
            'required' => false,
            'allowEmpty' => true
        )));
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-04-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-04-07
      • 1970-01-01
      • 2014-03-05
      相关资源
      最近更新 更多