title: How to do a form in some steps in Symfony2 - Step Validation
body: <p>I would like doing a form in some steps in Symfony2 (2.3 exactly), but when I try to do this, I get an error in my form.</p>
  
  <p>I have done the next:</p>
  
  <p>1) I've created a class</p>
  
  <pre><code>class MyClass
  {
  /**
   * @var integer
   *
   * @ORM\Column(name="id", type="integer")
   * @ORM\Id
   * @ORM\GeneratedValue(strategy="AUTO")
   */
  private $id;
  
  /**
   * @var string
   *
   * @ORM\Column(name="name", type="string", length=255)
   * @Assert\NotNull()
   */
  private $name;
  
  /**
   * @var string
   *
   * @ORM\Column(name="surname", type="string", length=255)
   * @Assert\NotNull()
   */
  private $surname;
  }
  </code></pre>
  
  <p>2) I've created the FormType class:</p>
  
  <pre><code>class MyClassType extends AbstractType
  {
  public function buildForm(FormBuilderInterface $builder, array $options)
  {
      $builder
          -&gt;add('name', null, array('label' =&gt; 'name'))
          -&gt;add('surname', null, array('label' =&gt; 'surname'));     
  }
  </code></pre>
  
  <p>And I have created 2 more classes to separate the process for getting the data of the form:</p>
  
  <pre><code>class MyClass1Type extends AbstractType
  {
  public function buildForm(FormBuilderInterface $builder, array $options)
  {
      $builder
          -&gt;add('name', null, array('label' =&gt; 'name'));     
  }
  
  class MyClass2Type extends AbstractType
  {
  public function buildForm(FormBuilderInterface $builder, array $options)
  {
      $builder
          -&gt;add('surname', null, array('label' =&gt; 'surname'));     
  }
  </code></pre>
  
  <p>And in the controller I have some methods:</p>
  
  <pre><code>public function new1Action()
  {
      $entity = new MyClass();
      $form   = $this-&gt;createForm( new MyClass1Type( $entity );
  
      return array(
          'entity' =&gt; $entity,
          'form'   =&gt; $form-&gt;createView(),
      );
  }
  
  public function new2Action(Request $request)
  {
      $entity  = new MyClass();
      $formMyClass1 = $this-&gt;createForm(new MyClass1Type($entity) );
      $formMyClass1-&gt;bind($request);
  
      if (!$formMyClass1-&gt;isValid()) {
          print_r($formMyClass1-&gt;getErrors());
          return new Response("Error");
      }
  
      $form   = $this-&gt;createForm( new MyClass2Type($entity) );
  
      return array(
          'entity' =&gt; $entity,
          'form'   =&gt; $form-&gt;createView(),
      );
  }
  </code></pre>
  
  <p>I render the first form (new1Action) and it get the data perfectly, but the problem is when I submit the data. In the new2Action, the application goes throw the response("error") code, because the form is not valid. The print_r() function shows the next information:</p>
  
  <pre><code>Array ( [0] =&gt; Symfony\Component\Form\FormError Object ( [message:Symfony\Component\Form\FormError:private] =&gt; Este valor no deberÃ­a ser null. [messageTemplate:protected] =&gt; This value should not be null. [messageParameters:protected] =&gt; Array ( ) [messagePluralization:protected] =&gt; ) ) 
  </code></pre>
  
  <p>I think that the problem is that the class is not complete with the data got in the first form, but I need to separate the form in two steps and I have no idea how deal with this error.</p>
  
  <p>Could someone help me?</p>
  
  <p>Thanks in advance. </p>