我有一个2选择的表格.基于第一个选择的值,它使用AJAX更新第二个选择的值.这样做会使表单无效.所以,我做了下一个改变:
$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
}
Run Code Online (Sandbox Code Playgroud)
基本上,我检查它是否有效,如果用户更改了第一个选择的值,则不会.我得到填充第二个选择的选项,并用它们填充表单.然后我尝试再次验证它.但这不起作用.任何人都可以解释为什么?存在相同的"在大海捞针中找不到的价值".
Joe*_*ord 31
您可以尝试停用验证器:
在你的Form.php中
$field = $this->createElement('select', 'fieldname');
$field->setLabel('Second SELECT');
$field->setRegisterInArrayValidator(false);
$this->addElement($field);
Run Code Online (Sandbox Code Playgroud)
第三行将停用验证器,它应该工作.
Ons*_*hop 11
您还可以使用'disable_inarray_validator'=> true禁用InArray验证器:
例如:
$this->add( array(
'name' => 'progressStatus',
'type' => 'DoctrineModule\Form\Element\ObjectSelect',
'options' => array(
'disable_inarray_validator' => true,
),
));
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
17518 次 |
| 最近记录: |