在表单上我添加一个这样的字段
$builder->add('cse',
ChoiceType::class,
array(
'label' => '',
'required' => true,
'translation_domain' => 'messages',
'choices' => array(
'I agree' => true
),
'expanded' => true,
'multiple' => true,
'data' => null,
'attr' => array( 'class' => 'form_f' ),
)
)
虽然添加到表单中的所有其他字段将“required”设置为“true”将阻止发送表单,但该字段的 required 属性将被忽略(无论是否选中,表单都会发送)。
我必须用 Assert 语句来处理这个问题吗?如果是 - 仍然:为什么需要不在这里工作?
最佳答案
是的,使用断言。
因为multiple=true
打印checkbox
。 Html 验证器可以测试 radio
,但不能测试 checkbox
。
始终对所有表单使用 Assert,因为 html 验证器不安全:)
关于forms - Symfony 表单 ChoiceType 忽略必需的属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49054266/