运行带有Symfony Forms的Symfony 4,我已经在表单构建器中定义了一个文本字段:
public function buildForm(FormBuilderInterface $builder, array $options): void
{
// .... other fields
$builder->add('referralCode', TextType::class, [
'required' => true,
'label' => 'Referral Code',
'constraints' => [new NotBlank()],
'attr' => [
'placeholder' => 'Enter a six figures Referral Code (e.g. "6EQE7M")'
]
]);
}
根据文档和教程,此处应使用NotBlank约束。但是,它不起作用。如果我提交的表单中没有在此文本字段中键入任何数据,则不会显示任何错误。而是将空值发送到实体的属性中。
这里还需要做什么?