Overriding Form Validation messages on symfony2

前端 未结 2 858
被撕碎了的回忆
被撕碎了的回忆 2021-01-04 18:21

How to override the form validation messages in symfony2. Though there is a validation.xml file related model classes. I think it validates a form based on html5.

2条回答
  •  失恋的感觉
    2021-01-04 19:05

    You can change the message of each validator thanks to the message option when declaring the assert:

    /**
         * @ORM\Column(type="string", length=255, unique=true)
         * @Assert\NotBlank(
         *     message="You have to choose a username (this is my custom validation message).",
         *     groups={"registration", "account", "oauth"}
         * )
    

    Also you can apply translation by creating the file MyBundle/Resources/translations/validators.fr.xliff

提交回复
热议问题