symfony: Form submit don't process validation

Symfony version(s) affected: 4.2.2

Description
When i submit form manually validation don’t work. According to documentation , one submit manually the form is validate

How to reproduce

public function registerUsers(Request $request,$type ,EventDispatcherInterface $dispatcher) {
        $map = ["coach" => Coach::class,"player" => Player::class,"supporter" => Supporter::class];
        $em = $this->getDoctrine()->getManager();
        /** @var User $user */
       $user =  new $map[$type]();
        $dispatcher->dispatch(AppEventType::AUTH_INITIALIZE_REGISTER,new UserEvent($user,$request));

       $options = ["validation_groups" => "register","data_class" => $map[$type]];
        /** @var FormInterface $form */
       $form = $this->createForm(UserType::class,$user,$options);
       $dispatcher->dispatch(AppEventType::AUTH_BEFORE_SUBMIT_FORM_REGISTER,new FormUserEvent($form,$user,$request));
        // $form->handleRequest($request);
        $form->submit($request->request->all(),false);

        $dispatcher->dispatch(AppEventType::AUTH_AFTER_SUBMIT_FORM_REGISTER,new FormUserEvent($form,$user,$request));

       if($form->isValid()){
           /** @var EventDispatcher $dispatcher */
           $dispatcher->dispatch(AppEventType::AUTH_BEFORE_SAVE_USER,new UserEvent($user,$request));

           $em->persist($user);

           $em->flush();

           $dispatcher->dispatch(AppEventType::AUTH_AFTER_SAVE_USER,new UserEvent($user,$request));

       }
       return $this->handleView(View::create($form->getErrors()));
    }

Possible Solution

Additional context

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 2
  • Comments: 18 (8 by maintainers)

Most upvoted comments

https://github.com/symfony/symfony/issues/30235#issuecomment-464158265 It works, thank you. That’s because I put the second option of submit () to false

$form->isValid() always true?