Zend: Form validation: value was not found in the haystack error

后端 未结 4 1095
暗喜
暗喜 2021-02-13 03:48

I have a form with 2 selects. Based on the value of the first select, it updates the values of the second select using AJAX. Doing this makes the form not being valid. So, I mad

4条回答
  •  我寻月下人不归
    2021-02-13 04:05

    Additionaly you should add you own InArray Validator in order to protect your db etc.

    In Zend Framework 1 it looks like this:

    $this->addElement('select', $name, array(
                'required' => true,
                'label' => 'Choose sth:',
                'filters' => array('StringTrim', 'StripTags'),
                'multiOptions' => $nestedArrayOptions,
                'validators' => array(
                    array(
                        'InArray', true, array(
                            'haystack' => $flatArrayOptionsKeys,
                            'messages' => array(
                                Zend_Validate_InArray::NOT_IN_ARRAY => "Value not found"
                            )
                        )
                    )
                )
            ));
    

    Where $nestedArrayOptions is you multiOptions and $flatArrayOptionsKeys contains you all keys.

提交回复
热议问题