【问题标题】:SF2: How to custom the form type messages?SF2:如何自定义表单类型的消息?
【发布时间】:2014-02-22 12:22:10
【问题描述】:

我想知道如何修改我的 ContactType 上的错误消息。 可以直接在 Type 中吗?

我当前的代码:

class ContactType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
       //...
    }

public function setDefaultOptions(OptionsResolverInterface $resolver)
    {
        $collectionConstraint = new Collection(array(
            'name' => array(
                new NotBlank(array('message' => 'My custon message.')),
                new Length(array('min' => 2), array('message' => 'My custon message.'))
            ),
            'email' => array(
                new NotBlank(array('message' => 'My custon message.')),
                new Email(array('message' => 'My custon message.'))
            ),
            'subject' => array(
                new NotBlank(array('message' => 'My custon message.')),
                new Length(array('min' => 10), array('message' => 'My custon message.'))
            ),
            'message' => array(
                new NotBlank(array('message' => 'My custon message')),
                new Length(array('min' => 5))
            )
        ));

        $resolver->setDefaults(array(
            'constraints' => $collectionConstraint
        ));
    }

    public function getName()
    {
        return 'contact';
    }
}

感谢大家的帮助。

最好的问候,

【问题讨论】:

    标签: regex symfony entity constraints validation


    【解决方案1】:

    建议改为更改断言的消息,但您也可以使用表单类型的invalid_message 设置。

    【讨论】:

      猜你喜欢
      • 2012-05-10
      • 2011-12-28
      • 1970-01-01
      • 2018-08-19
      • 2012-11-01
      • 1970-01-01
      • 2021-07-16
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多