How to add a translated validation message to a form without entity with Symfony 2.3 -


i'm using symfony 2.3.
have simple contact form , add custom translated validation messages, (but don't have entity) :

class author {     /**      * @assert\notblank(message = "author.name.not_blank")      */     public $name; } 

i have done :

namespace me\mybundle\form\type;  use symfony\component\form\abstracttype; use symfony\component\form\formbuilderinterface; use symfony\component\optionsresolver\optionsresolverinterface; use symfony\component\validator\constraints\notblank;  class contacttype extends abstracttype {      public function buildform(formbuilderinterface $builder, array $options) {         $builder         ->add('name', 'text', array('constraints' => new notblank(array('message' => "contact.name.not_blank")),)) ; 

where in me/mybundle/resources/translations, have added in "validators.fr.yml" :

contact.name.not_blank: "please enter name." 

the message "contact.name.not_blank",

class contacttype extends abstracttype {      public function buildform(formbuilderinterface $builder, array $options) {         $builder         ->add('name', 'text', array('constraints' =>               new notblank(array('message' =>                  $this->get('translator')->trans('contactname_notblank'))),     )); 

and english translation yaml file:

// appbundle/resources/translations/messages.en.yml contactname_notblank: name field required! 

Comments

Popular posts from this blog

javascript - gulp-nodemon - nodejs restart after file change - Error: listen EADDRINUSE events.js:85 -

Fatal Python error: Py_Initialize: unable to load the file system codec. ImportError: No module named 'encodings' -

javascript - oscilloscope of speaker input stops rendering after a few seconds -