title: A form that is never valid - Symfony2
body: <p>I have a class Products which I use for a form and for the database - it has 3 date fields with this or similar: </p>
  
  <pre class="lang-php prettyprint-override"><code>/**
   * @ORM\Column(name="`date`", type="date")
   * @Assert\NotBlank()
   * @Assert\Type("\Date")
   */
  </code></pre>
  
  <p>It has also 3-4 other fields which has only <code>NotBlank()</code>, one without any constraints and a field which is used to save the category of the product (category is another class and table in the database). It looks like this:</p>
  
  <pre class="lang-php prettyprint-override"><code>/**
   * @ORM\ManyToOne(targetEntity="Categories")
   * @ORM\JoinColumn(name="categories_id", referencedColumnName="id")
   **/
  private $categories;
  </code></pre>
  
  <p>Here is my function: </p>
  
  <pre class="lang-php prettyprint-override"><code>public function addAction($id, Request $request)
  {
      $em = $this-&gt;getDoctrine()-&gt;getEntityManager(); 
      $products = new Products();
      $products_form = $this-&gt;createForm(new ProductsType(), $products);  
      $category = $em-&gt;getRepository('AcmeMyBundle:Categories')-&gt;find($id);
  
      if($request-&gt;getMethod() == 'POST')
      {
          $products_form-&gt;bindRequest($request);
  
          if($products_form-&gt;isValid()) 
          {
              $products-&gt;setDomains($category); 
              $em-&gt;persist($products);
              $em-&gt;flush();
          }
  </code></pre>
  
  <p>At the end it redirects. The problem is that even when I add correct values in the form it says that it is not valid. To add a date a simply write a string like this '2012-08-09' in the form.</p>
  
  <p>When I comment </p>
  
  <pre><code>if($products_form-&gt;isValid())
  </code></pre>
  
  <p>Everything works fine. </p>
  
  <p>Any suggestions? Please help!</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>Here is the Products class:</p>
  
  <pre class="lang-php prettyprint-override"><code>/**
   * @ORM\Entity
   * @ORM\Table(name="products")
   */
  class Products
  {
  /**
   * @ORM\Id
   * @ORM\Column(type="integer")
   * @ORM\GeneratedValue(strategy="AUTO")
   */
  protected $id;
  
  /**
   * @ORM\ManyToOne(targetEntity="Categories")
   * @ORM\JoinColumn(name="categories_id", referencedColumnName="id")
   **/
  private $categories;
  
  /**
   * @ORM\Column(name="`date`", type="date")
   * @Assert\NotBlank()
   * @Assert\Type("\Date")
   */
  protected $date;
  
  /**
   * @ORM\Column(name="`from`", type="date")
   * @Assert\NotBlank()
   * @Assert\Type("\Date")   
   */
  protected $from;
  
  /**
   * @ORM\Column(name="`to`", type="date")
   * @Assert\NotBlank()
   * @Assert\Type("\Date")
   */
  protected $to;
  
  /**
   * @ORM\Column(type="decimal", scale=2)
   * @Assert\NotBlank()
   */
  protected $price;
  
  /**
   * @ORM\Column(type="string", length=5)
   * @Assert\NotBlank()
   */
  protected $currency;
  
  /**
   * @ORM\Column(type="string", length=50)
   * @Assert\NotBlank()
   */
  protected $paymentid;
  
  /**
   * @ORM\Column(type="string", length=100, nullable=true)
   */
  protected $notes;
  </code></pre>
  
  <p>And here I create the form:</p>
  
  <pre class="lang-php prettyprint-override"><code>class ProductsType extends AbstractType
  {
  public function buildForm(FormBuilder $builder, array $options)
  {
      $builder-&gt;add('date', 'date', array(
          'widget' =&gt; 'single_text', 
          'format' =&gt; 'yyyy-MM-dd'));
  
      $builder-&gt;add('from', 'date', array(
          'widget' =&gt; 'single_text', 
          'format' =&gt; 'yyyy-MM-dd'));
  
      $builder-&gt;add('to', 'date', array(
          'widget' =&gt; 'single_text', 
          'format' =&gt; 'yyyy-MM-dd'));
  
      $builder-&gt;add('price', 'text');
  
      $builder-&gt;add('currency', 'choice', array(
          'choices' =&gt; array(
              'empty_value'=&gt;'--- Choose ---', 'USD'=&gt;'USD', 'HKD'=&gt;'HKD', 'EUR'=&gt;'EUR', 'BGN'=&gt;'BGN')));
  
      $builder-&gt;add('paymentid', 'text');
  
      $builder-&gt;add('notes', 'text', array(
          'required'  =&gt; false));
  }
  
  public function getName()
  {
      return 'payments';
  }
  </code></pre>