我已经阅读了许多针对 Zend Framework 缺乏默认复选框验证的解决方法。
我最近开始使用 ZF2,但文档有点缺乏。
有人可以演示如何使用 Zend 表单和验证机制验证复选框以确保其被选中吗?我正在为我的表单使用数组配置(使用 ZF 网站上的示例应用程序中找到的默认设置)。
Try this
表单元素:
$this->add(array(
'type' => 'Zend\Form\Element\Checkbox',
'name' => 'agreeterms',
'options' => array(
'label' => 'I agree to all terms and conditions',
'use_hidden_element' => true,
'checked_value' => 1,
'unchecked_value' => 'no'
),
));
在过滤器中,添加数字验证
use Zend\Validator\Digits; // at top
$inputFilter->add($factory->createInput(array(
'name' => 'agreeterms',
'validators' => array(
array(
'name' => 'Digits',
'break_chain_on_failure' => true,
'options' => array(
'messages' => array(
Digits::NOT_DIGITS => 'You must agree to the terms of use.',
),
),
),
),
)));
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)