title: Entity persists even when form has error
body: <p>I have an issue where I have a form type that persists the associated entity even when the form is not valid.
  I have confirmed that the form indeed has errors via $form->getErrorsAsString(). I have also confirmed that the logical if statement that checks if the form is valid or not comes out false. The entity still persists despite the fact that the form is never valid.</p>
  
  <p>I'm not sure what I'm doing wrong here as I have no other spot that I can find that either persists the entity or flushes the entity manager. Here's my controller:</p>
  
  <pre><code>/**
   * @Route("/settings/profile", name="settings_profile")
   * @Template();
   */
  public function profileAction()
  {
      $user = $this-&gt;getUser();
      $profile = $user-&gt;getUserProfile();
  
      if (null === $profile) {
          $profile = new UserProfile();
          $profile-&gt;setUser($user);
          $profileDataModel = $profile;
      } else {
          $profileDataModel = $this-&gt;getDoctrine()-&gt;getManager()-&gt;find('MyAppBundle:UserProfile',$profile-&gt;getId());
      }
  
      $form = $this-&gt;createForm(new ProfileType(),$profileDataModel);
      $request = $this-&gt;getRequest();
  
      if ($request-&gt;getMethod() === 'POST') {
          $form-&gt;bind($request);
  
          if ($form-&gt;isValid()) {
              // This logic never gets executed!
              $em = $this-&gt;getDoctrine()-&gt;getManager();
              $profile = $form-&gt;getData();
              $em-&gt;persist($profile);
              $em-&gt;flush();
              $this-&gt;get('session')-&gt;setFlash('profile_saved', 'Your profile was saved.');
              return $this-&gt;redirect($this-&gt;generateUrl('settings_profile'));
          }
      }
  
      return array(
          'form'      =&gt;  $form-&gt;createView(),
      );
  }
  </code></pre>