禁用notInArray Validator Zend Framework 2

时间:2022-10-10 12:10:26

Is there a way to disable notInArray Validator in Zend Framework 2. All the info on the internet shows how to disable the notInArray Validator in Zend Framework 1, for example in this fashion

有没有办法在Zend Framework 2中禁用notInArray Validator.Internet上的所有信息都显示了如何在Zend Framework 1中禁用notInArray Validator,例如以这种方式

If you do not want the InArray validator at all, you can disable this behavior by either calling setRegisterInArrayValidator(false) on the element, or by passing false to the registerInArrayValidator configuration key on element creation.

如果您根本不需要InArray验证器,则可以通过在元素上调用setRegisterInArrayValidator(false)或在元素创建时将false传递给registerInArrayValidator配置键来禁用此行为。

One the posts in * can be found here

可以在此处找到*中的一个帖子

Unfortunately this is not possible in Zend Framework 2. So in case if anybody has a tip how this can be disabled.

不幸的是,这在Zend Framework 2中是不可能的。因此,如果有人有提示,如何禁用它。

5 个解决方案

#1


9  

Since version 2.2, Zend Framework provide the ability to disable inArray validator calling:

从版本2.2开始,Zend Framework提供了禁用inArray验证器调用的功能:

$element->setDisableInArrayValidator(false);

or passing option to an element:

或者将选项传递给元素:

'disable_inarray_validator' => false

#2


2  

I had the same problem and what i did is populate the element before validate it, for example:

我有同样的问题,我做的是在验证之前填充元素,例如:

$clientForm->get('city')->setValueOptions($options);
$clientForm->setData($post);

if ($clientForm->isValid()) {
  //
} else {
  //
}

This don't disable notInArray valitador but you can trick it.

这不会禁用notInArray valitador,但你可以欺骗它。

#3


0  

I came with the same case : while i was populating my html select element via ajax after alot of searching found no way to do it , ending with creating my own select form element , I will provide you with my changes :

我带来了同样的情况:当我通过ajax填充我的html选择元素后,很多搜索没有办法做到这一点,最后创建我自己的选择表单元素,我将为您提供我的更改:

    /**
     * Provide default input rules for this element
     *
     * Attaches the captcha as a validator.
     *
     * @return array
     */
    public function getInputSpecification()
    {
        $spec = array(
            'name' => $this->getName(),
            'required' => true,
            //// make sure to delete the validators array in the next line  
            'validators' => array( 
                $this->getValidator()
            )
        );

        return $spec;
    }

#4


0  

I found this at this link and thought I would post it as I found it a great solution .... http://samsonasik.wordpress.com/2012/10/01/zend-framework-2-extending-zendform-to-add-select-multicheckbox-emaildate-textarea-and-radio-element/

我在这个链接上找到了这个链接并认为我会发布它,因为我发现它是一个很好的解决方案.... http://samsonasik.wordpress.com/2012/10/01/zend-framework-2-extending-zendform-to -add选-multicheckbox-emaildate-textarea的-AND-RADIO-元件/

don’t try to deactive the default validator. re-values the select options values before setData.

不要试图使默认验证器失效。在setData之前重新定义选择选项值。

$form->get('state_id')
     ->setOptions(
           array('value_options'=> $Newstatecollection)) ;

Saves the mess of deactivating the function if you need it elsewhere

如果您在其他地方需要,可以省去停用该功能的麻烦

#5


0  

If you don't need validation at all, add required => false in InputFilter

如果您根本不需要验证,请在InputFilter中添加required => false

    $this->add(array(
        'name' => 'your-elements-name',
        'required' => false,
    ));

worked for me..

为我工作..

#1


9  

Since version 2.2, Zend Framework provide the ability to disable inArray validator calling:

从版本2.2开始,Zend Framework提供了禁用inArray验证器调用的功能:

$element->setDisableInArrayValidator(false);

or passing option to an element:

或者将选项传递给元素:

'disable_inarray_validator' => false

#2


2  

I had the same problem and what i did is populate the element before validate it, for example:

我有同样的问题,我做的是在验证之前填充元素,例如:

$clientForm->get('city')->setValueOptions($options);
$clientForm->setData($post);

if ($clientForm->isValid()) {
  //
} else {
  //
}

This don't disable notInArray valitador but you can trick it.

这不会禁用notInArray valitador,但你可以欺骗它。

#3


0  

I came with the same case : while i was populating my html select element via ajax after alot of searching found no way to do it , ending with creating my own select form element , I will provide you with my changes :

我带来了同样的情况:当我通过ajax填充我的html选择元素后,很多搜索没有办法做到这一点,最后创建我自己的选择表单元素,我将为您提供我的更改:

    /**
     * Provide default input rules for this element
     *
     * Attaches the captcha as a validator.
     *
     * @return array
     */
    public function getInputSpecification()
    {
        $spec = array(
            'name' => $this->getName(),
            'required' => true,
            //// make sure to delete the validators array in the next line  
            'validators' => array( 
                $this->getValidator()
            )
        );

        return $spec;
    }

#4


0  

I found this at this link and thought I would post it as I found it a great solution .... http://samsonasik.wordpress.com/2012/10/01/zend-framework-2-extending-zendform-to-add-select-multicheckbox-emaildate-textarea-and-radio-element/

我在这个链接上找到了这个链接并认为我会发布它,因为我发现它是一个很好的解决方案.... http://samsonasik.wordpress.com/2012/10/01/zend-framework-2-extending-zendform-to -add选-multicheckbox-emaildate-textarea的-AND-RADIO-元件/

don’t try to deactive the default validator. re-values the select options values before setData.

不要试图使默认验证器失效。在setData之前重新定义选择选项值。

$form->get('state_id')
     ->setOptions(
           array('value_options'=> $Newstatecollection)) ;

Saves the mess of deactivating the function if you need it elsewhere

如果您在其他地方需要,可以省去停用该功能的麻烦

#5


0  

If you don't need validation at all, add required => false in InputFilter

如果您根本不需要验证,请在InputFilter中添加required => false

    $this->add(array(
        'name' => 'your-elements-name',
        'required' => false,
    ));

worked for me..

为我工作..