【问题标题】:Embedded form skipping validation嵌入式表单跳过验证
【发布时间】:2016-02-22 17:16:54
【问题描述】:

我有一个用户实体,与信用卡实体(一对多)相关,我正在尝试为刚刚注册但尚未注册信用卡的用户编写一个表单。在上述表格中,用户应该填写他们第一张信用卡的信息。

下面的代码可以正常工作,在构建表单时,cvv 文本字段按预期显示“123”。

但是当我去提交表单时,信用卡数据没有被验证,只有用户数据,这是问题所在。

下面是一些相关的代码行,如果您需要更多部分,我会尽力提供缺少的部分。

<?php
// in the controller
$user->addCreditCard(new CreditCard());
// this actually shows up in the form.
$user->getCreditCards()[0]->setCvv(123);
// in the outer form type
$builder->add(
    'credit_card',
    CollectionType::class,
    [
        'type' => CreditCardType::class,
        'property_path' => 'creditCards',
        'entry_options' => [
            //'validation_groups' => ['credit_card'],
            'container' => $container,
            // this is just me being desperate
            'constraints' => [new Assert\Valid(), new Assert\NotBlank()],
        ],
    ]
)
// Inner form type 
// This is extra, just to test if the failure happens at entity level. But this check is ignored.
$builder->add('number', TextType::class, ['constraints' => [new Assert\NotBlank()]]);

【问题讨论】:

    标签: symfony symfony-forms symfony-validator


    【解决方案1】:

    问题出在验证组中,我用小写的 d 拼写了 default。显然他们对大小写非常敏感。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-08-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-06-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多