Symfony形式ChoiceType忽略了必需的属性

问题描述 投票:0回答:1

在表单上我添加了这样的字段

$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”的表单中的所有其他字段将阻止表单被发送,但忽略该字段的必需属性(无论是否选中,表单都会被发送)。

我是否必须使用Assert语句处理此问题?如果是 - 仍然:为什么要求不在这里工作?

forms symfony validation symfony-3.3 symfony3.x
1个回答
1
投票

是的,使用Assert。

因为multiple=true打印checkbox。 Html验证器可以测试radio,但没有checkbox

始终对所有表单使用Assert,因为html验证器不安全:)

© www.soinside.com 2019 - 2024. All rights reserved.