我在复选框验证方面遇到了一个奇怪的问题。它总是无效...我已经阅读了很多有关此问题的内容,但我找不到解决方案...(我在验证中使用 array_keys )
所以,这是我的代码:
class NetworkDevicesAndInterfacesForm extends sfForm {
public function configure() {
$optionsArr = array('one' => 'One','two' => 'Two');
$this->setWidgets(array(
'devices' => new sfWidgetFormChoice(array(
'expanded' => true,
'multiple' => true,
'choices' => $optionsArr),
array('class' => 'checkbox'))
));
$this->setValidators(array(
'devices' => new sfValidatorChoice(array(
'choices' => array_keys($optionsArr)),
array('required' => 'Please choose something!'))
));
$this->widgetSchema->setLabels(array(
'devices' => ' '
));
$this->widgetSchema->setNameFormat('devices[%s]');
}
}
Action:
if ($request->isMethod('post')) {
$this->form->bind($request->getParameter('devices'));
if ($this->form->isValid()) {
$formValues = $this->form->getValues();
$deviceId = $formValues['devices'];
}
}
在小部件选项中指定“多个”时,您应该对相应的验证器执行相同的操作:
$this->setValidators(array(
'devices' => new sfValidatorChoice(array(
'choices' => array_keys($optionsArr),
'multiple' => true
),
array('required' => 'Please choose something!'))
));
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)