To be able do deal with form events, it's important to attach the request, that is send to a controller action after submitting a form, to the form created in that action.
public function registerAction(Request $request)
{
$data = new ExampleObject();
$form = $this->createForm(ExampleObjectType::class, $data);
$form->handleRequest($request);
if($form->isSubmitted() && $form->isValid()){
// do something with form data
return $this->redirectToRoute('route_name');
}
return $this->render('view.html.twig', array(
'form' => $form->createView()
));
}
The request variable passed to the action is of type Symfony\Component\HttpFoundation\Request