gpt4 book ai didi

symfony - 当使用 symfony 2's form type "集合时,如何验证至少已提交一份表单?

转载 作者:行者123 更新时间:2023-12-02 09:05:27 25 4
gpt4 key购买 nike

我用了this tutorial嵌入表单集合。如何添加验证以确保表单至少与一张表单一起提交?

最佳答案

Symfony 现在有一个 Count 约束,可以与集合类型一起使用来设置最小项目数:

use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\Form\Extension\Core\Type\CollectionType;

$formBuilder->add('example', CollectionType::class, [
// other options...
'constraints' => [
new Assert\Count([
'min' => 1,
'minMessage' => 'Must have at least one value',
// also has max and maxMessage just like the Length constraint
]),
],
]);

关于symfony - 当使用 symfony 2's form type "集合时,如何验证至少已提交一份表单?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10572672/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com