1

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

        $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。我该怎么办?

4

1 回答 1

0

试试看

    $inputFilter->add($factory->createInput(array(
        'name' => 'services',
        'required' => false,
        'allowEmpty' => true
    )));
于 2013-04-27T13:52:00.417 回答