本文介绍了Zend:表单验证:在 haystack 错误中找不到值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含 2 个选择的表单.根据第一个选择的值,它使用 AJAX 更新第二个选择的值.这样做会使表单无效.所以,我做了下一个改变:

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 made the next change:

        $form=$this->getAddTaskForm(); //the form

        if(!$form->isValid($_POST)) {
            $values=$form->getValues();

            //get the options and put them in $options

                $assignMilestone=$form->getElement('assignedMilestone');
                $assignMilestone->addMultiOptions($options);

        }

        if($form->isValid($_POST)) {
               //save in the database
            }else {
               //redisplay the form
            }

基本上,我检查它是否有效,如果用户更改了第一个选择的值则无效.我得到了填充第二个选择的选项并用它们填充表单.然后我尝试再次验证它.然而这行不通.任何人都可以解释为什么?存在相同的在大海捞针中找不到值".

Basically, I check if it is valid and it isn't if the user changed the value of the first select. I get the options that populated the second select and populate the form with them. Then I try to validate it again. However this doesn't work. Anybody can explain why? The same "value was not found in the haystack" is present.

推荐答案

您可以尝试停用验证器:

You could try to deactivate the validator:

在你的 Form.php 中

in your Form.php

$field = $this->createElement('select', 'fieldname');
$field->setLabel('Second SELECT');
$field->setRegisterInArrayValidator(false);
$this->addElement($field);

第三行将停用验证器,它应该可以工作.

The third line will deactivate the validator and it should work.

这篇关于Zend:表单验证:在 haystack 错误中找不到值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-03 18:55