src/Controller/ContactController.php line 18

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\ContactUs;
  4. use App\Form\ContactType;
  5. use Doctrine\Persistence\ManagerRegistry;
  6. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  7. use Symfony\Component\HttpFoundation\Request;
  8. use Symfony\Component\HttpFoundation\Response;
  9. use Symfony\Component\Routing\Annotation\Route;
  10. class ContactController extends AbstractController
  11. {
  12. /**
  13. * @Route("/contact-us", name="contact")
  14. */
  15. public function index(Request $request, ManagerRegistry $registry): Response
  16. {
  17. $contact = new ContactUs();
  18. $form = $this->createForm(ContactType::class, $contact, [
  19. 'attr' => [
  20. 'id' => 'contactForm',
  21. 'data-toggle' => 'validator',
  22. 'class' => 'shake',
  23. ],
  24. ]);
  25. $form->handleRequest($request);
  26. if ($form->isSubmitted() && $form->isValid()) {
  27. $entityManager = $registry->getManager();
  28. $entityManager->flush();
  29. return $this->redirectToRoute('contact', [], Response::HTTP_SEE_OTHER);
  30. }
  31. return $this->render('contact/index.html.twig', [
  32. 'controller_name' => 'ContactController',
  33. 'form' => $form->createView(),
  34. ]);
  35. }
  36. }