Symfony 3.20
When you create your FormType, in the controller, follow the route and actions as shown below, use "if ($ formRegister-> isSubmitted () && $ formRegister-> getClickedButton ('form2') & & ...)"
class WelcomeController extends Controller { /** * @Route("/welcome", name="welcome") */ public function welcomeAction(Request $request) { $uLogin = new User(); $formLogin = $this->createForm(LoginUserFormType::class, $uLogin); $uRegister = new User(); $formRegister = $this->createForm(UserRegistrationFormType::class, $uRegister); $authenticationUtils = $this->get('security.authentication_utils'); $error = $authenticationUtils->getLastAuthenticationError(); // last username entered by the user $lastUsername = $authenticationUtils->getLastUsername(); if ($request->isMethod('post')){ $formLogin->handleRequest($request); $formRegister->handleRequest($request); if($formLogin->isSubmitted() && $formLogin->getClickedButton('form1')){ return $this->redirectToRoute('login_success'); } if ($formRegister->isSubmitted() && $formRegister->getClickedButton('form2') && $formRegister->isValid() ) { $password = $this->get('security.password_encoder') ->encodePassword($uRegister, $uRegister ->getPlainPassword()); $uRegister ->setPassword($password); $uRegister->setRole('ROLE_USER'); $em = $this ->getDoctrine() ->getManager(); $em -> persist($uRegister); $em -> flush(); return $this->redirectToRoute('register_success'); } } return $this->render( 'form/welcome.html.twig', array( 'form1' => $formLogin -> createView(), 'form2' => $formRegister -> createView(), 'last_username' => $lastUsername, 'error' => $error, ) ); }
Create your own routing, and that is it :-)
zoore source share