Q:

Symfony - Set Data with Form Even Listener

I have a register form. 
When the form is submitted and valid there is a bunch of validation happening like checking if the password  and password_confirm match. 
If not I redirect to the same page with the error message. 
But I don't want my user to loose all the data he already filled. 
How can I fill the form with those data. Should I use a FormEventListener? 
public function register(Request $request, RegisterHandler $registerHandler, Register $register)
{
    if($this->getUser()){
        return $this->redirectToRoute('homepage');
    }

    $form = $this->createForm(RegisterType::class, $register);

    $form->handleRequest($request);
    if ($form->isSubmitted() && $form->isValid()) {
        try{
            $registerHandler->handle($form->getData());
        }catch (UserAlreadyExistException $e){
            $this->addFlash('error', $e->getMessage());
            return $this->redirectToRoute('register');
        }catch (PasswordMatchingException $e){
            $this->addFlash('error', $e->getMessage());
            return $this->redirectToRoute('register');
        }

        return $this->redirectToRoute('homepage');
    }

    return $this->render('app/pages/login/register.html.twig', [
        'form' => $form->createView(),
    ]);
}

My Form Type
public function buildForm(FormBuilderInterface $builder, array $options)
{
    $builder
        ->add('firstName', TextType::class, [
            'required' => true,
            'label' => 'Your Name',
            'attr' => [
                'class' => 'form-control',
            ]
        ])
        ->add('lastName', TextType::class, [
            'required' => true,
            'label' => 'Your Last Name',
            'attr' => [
                'class' => 'form-control',
            ]
        ])
        ->add('email', EmailType::class, [
            'required' => true,
            'label' => 'Your Email',
            'attr' => [
                'class' => 'form-control',
            ]
        ])
        ->add('password', PasswordType::class, [
            'required' => true,
            'label' => 'Your password',
            'attr' => [
                'id' => 'password1',
                'class' => 'form-control',
            ]
        ])
        ->add('passwordConfirm', PasswordType::class, [
            'required' => true,
            'label' => 'Confirm password',
            'attr' => [
                'id' => 'password2',
                'class' => 'form-control',
            ]
        ])
    ;

    $builder->addEventListener(FormEvents::POST_SUBMIT, function (FormEvent $event) {
        $data = $event->getData();
        $form = $event->getForm();

        //@TODO
    });
}

public function configureOptions(OptionsResolver $resolver)
{
    $resolver->setDefaults([
        'data_class' => Register::class,
    ]);
}

A:

Where do PasswordMatchingException and UserAlreadyExistException come from?
Usually you would use a constraint or write your own validator, then $form->isValid() would be false and the form would be rendered again with the same data and display the errors. For UserAlreadyExistException you would use @UniqueEntity("email") and for passwords you should use RepeatedType.

