title: SYMFONY 3 form validation with choiceType "This value is not valid. "
body: <p>I have two entities Contact and Cities no relationship between the two entities, when the user he entered the zip code the combobox is filled automatically using a script ajax there all is well.</p>
  
  <p>At the time of adding to the database, I have this error 'This value is not valid.</p>
  
  <pre><code>  class Contact
       {
  /**
   * @var integer
   *
   * @ORM\Column(name="id", type="integer", nullable=false)
   * @ORM\Id
   * @ORM\GeneratedValue(strategy="IDENTITY")
   */
  private $id;
  
  /**
   * @var string
   *
   * @ORM\Column(name="content", type="string", length=255, nullable=false)
   */
  private $content;
  
  
  
  /**
   * @var string
   *
   * @ORM\Column(name="ville", type="string", length=255, nullable=false)
   */
  private $ville;
  
  /**
   * @var string
   *
   * @ORM\Column(name="pays", type="string", length=255, nullable=false)
   */
  private $pays;
  </code></pre>
  
  <p>ContactType:</p>
  
  <pre><code>  public function buildForm(FormBuilderInterface $builder, array $options)
  {
      $builder-&gt;add('content',null,array('attr'=&gt;array('class'=&gt;'cp','maxenght'=&gt;5)))
              -&gt;add('ville',ChoiceType::class,array('attr'=&gt;array('class'=&gt;'ville',
              )))
              -&gt;add('pays',null,array('attr'=&gt;array('class'=&gt;'pays')))
              -&gt;add('save',      SubmitType::class)
      ;
  
  
  
  }
  </code></pre>
  
  <p>VilleAction:</p>
  
  <pre><code>public function villesAction(Request $request, $cp){
  
  
  if ($request-&gt;isXmlHttpRequest()){
       $em = $this-&gt;getDoctrine()-&gt;getManager();
      $villeCodePostal = $em-&gt;getRepository('JTCUserBundle:Villes')-
  &gt;findBy(array('villeCodePostal'=&gt;$cp));
  
      if ($villeCodePostal){
  
          $villes = array();
          $pays = array();
  
          foreach ($villeCodePostal as $ville ){
  
              $villes[] = $ville-&gt;getVilleNom();
              $pays[]=$ville-&gt;getVilleDepartement();
  
          }
       //   $ville=$villeCodePostal-&gt;getVilleNom();
         // $pays=$villeCodePostal-&gt;getVilleDepartement();
  
      }else{
  
         $ville=null ;
         // $pays=null ;
      }
  
      $response = new JsonResponse();
  
  
        return $response-&gt;setData(array('ville'=&gt;$villes, 'pays'=&gt;$pays));//, 'pays'=&gt;$pays));
  
   } 
  }
  </code></pre>