如何在zend框架2中禁用inArray验证器表单

时间:2013-04-27 04:49:36

标签: forms validation zend-framework2

我在我的表格中使用它:

$this->add(array(     
    'type' => 'Zend\Form\Element\Select',       
    'name' => 'county',
    'registerInArrayValidator' => false,
    'attributes' =>  array(
        'id' => 'county',                
        'options' => array(
            //'null'=>'[Select county]',
        ),
    ),
    'options' => array(
        'label' => 'county',
    ),
));

并使用js设置value县字段。 验证后,我收到错误:haystack选项是必需的

3 个答案:

答案 0 :(得分:8)

将disable_inarray_validator添加到选项中:

$this->add(array(
    ...
    'options' => array(
        'disable_inarray_validator' => true,
        'label' => 'county',
    ),
));

答案 1 :(得分:2)

https://github.com/zendframework/zf2/blob/master/library/Zend/Form/Element/Select.php 有一个选项$disableInArrayValidator = false;以及相应的方法here

答案 2 :(得分:0)

在ZF1中,这是可行的:

// using the element instance:
$element->setRegisterInArrayValidator(false);

// or a configuration key as part of the options array:
'registerInArrayValidator' => false

// or
element.options.registerInArrayValidator = false
相关问题