zend 验证多选框
我在表单中使用 zend 验证,但无法验证表单中的多选框。
这是我在表单中的多选元素:
$days = new Zend_Form_Element_Select('day');
$days->setLabel('Days')
->addMultiOptions($total_days)
->setRequired(true)
->addValidator('NotEmpty')
->setAttrib('multiple', 'multiple');
即使我在多选框中选择了某些选项,我在表单提交期间也会收到以下错误:
在干草堆中找不到数组
我在 Zend/Validate/InArray.php 中看到以下代码,它只能验证单个表单元素,但不能验证数组:
public function isValid($value)
{
$this->_setValue($value);
if (in_array($value, $this->_haystack, $this->_strict))
{
return true;
}
}
但是我该如何解决该错误?
i am using zend validations in my form and i could not validate a multi select box in my form.
This is my multi select element in the form:
$days = new Zend_Form_Element_Select('day');
$days->setLabel('Days')
->addMultiOptions($total_days)
->setRequired(true)
->addValidator('NotEmpty')
->setAttrib('multiple', 'multiple');
I get the following error during form submission, even when i select some option in the multiselect box:
Array was not found in the haystack
And i see the following code in Zend/Validate/InArray.php, that can validate only single form elements, but not arrays:
public function isValid($value)
{
$this->_setValue($value);
if (in_array($value, $this->_haystack, $this->_strict))
{
return true;
}
}
But how can i resolve the error?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
要在表单中包含多选元素,您应该使用 Zend_Form_Element_Multiselect,而不是 Zend_Form_Element_Select,例如:
To have multi select elements in your form, you should be using Zend_Form_Element_Multiselect, not Zend_Form_Element_Select, eg: