Symfony confirmation form does not call

I am building a site with symfony2 and I have problems with validaiton form. It looks like the "isValid ()" method on my form is never called:

heres is my form creation:

public function createAction (request $ request) {$ pro = new Professionnel (); $ Created = False;

$form = $this->createFormBuilder($pro) ->add("raison_sociale",null,array("label"=>"Raison sociale * : ")) ->add("siret",null,array("label"=>"N° SIREN * : ")) ->add("nom",null,array("label"=>"Nom *: ")) ->add("prenom",null,array( "label"=>"Prénom *: " )) ->add("adresse",null,array( "required"=>false, "label"=>"Adresse : " )) ->add("code_postal","text",array( "required"=>false, "label"=> "Code Postal : " )) ->add("ville",null,array( "required"=>false, "label"=> "Ville : " )) ->add("tel",null,array("label"=>"Téléphone * : ","required"=>true)) ->add("mobile",null,array( "required"=>false, "label"=>"Mobile : " )) ->add("fax",null,array( "required"=>false, "label"=>"Fax : " )) ->add("email","email",array("label"=>"Email * : ")) ->add("username",null,array("label"=>"Login * : ")) ->add("password","password",array("label"=>"Mot de passe * : ")) ->add("newsletter",null,array("required"=>false,"label"=>"Je souhaite m'inscrire à la newsletter")) ->add("accept","checkbox",array("label"=>" ")) ->getForm() ; if ($request->isMethod("POST")) { $form->bind($request); if ($form->isValid()) { $em=$this->getDoctrine()->getEntityManager(); $pro=$form->getData(); $encoder = $this->get('security.encoder_factory')->getEncoder($pro); $pro->setPassword($encoder->encodePassword($pro->getPassword(),$pro->getSalt())); $em->persist($pro); $em->flush(); $created=true; $this->get("session")->getFlashBag()->add("success", "Votre compte a bien été créé. Vous avez reçu un mail confirmant votre inscritpion."); } } return $this->render('OverscanProfessionnelBundle:Front:create.html.twig',array('form'=>$form->createView(),'created'=>$created)); } 

and here is my validatio.yml:

 webapp\ProfessionnelBundle\Entity\Professionnel: constraints: Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity: fields: email message: "L'email est déjà pris" Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity: fields: username message: "Ce login est déjà pris" properties: raison_sociale: - Valid: siret: - Length: min : 9 max : 9 minMessage: "Le SIREN doit contenir 9 caractères" maxMessage: "Le SIREN doit contenir 9 caractères" - Regex: pattern: "/\d/" match: true message: "Le SIREN ne doit pas contenir de lettre" tel: - Length: min : 10 max : 10 minMessage: "Le numéro de téléphone doit contenir 10 chiffres" maxMessage: "Le numéro de téléphone doit contenir 10 chiffres" 

therefore, when I submit my form, no checks are called, but there are restrictions! Can someone help me please?

+4
source share
2 answers

Take a look at the " app /../config.yml "
You should see something like this:

 framework: ... validation: { enable_annotations: true } 

Set the value for this:

 framework: ... validation: { enabled: true, enable_annotations: true } 

And then your validation.yml file should be loaded!

+3
source

Try adding a data class to your form as follows:

 $this->createFormBuilder($entity, array( 'data_class' => '\Vendor\YourBundle\Entity\MyEntity', ) ) // -> add() 
0
source

Source: https://habr.com/ru/post/1491857/


All Articles