src/Controller/DefaultController.php line 25

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Form\ContactUsType;
  4. use App\Services\MailHandler;
  5. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  6. use Symfony\Component\HttpFoundation\Request;
  7. use Symfony\Component\HttpFoundation\Response;
  8. use Symfony\Component\Routing\Annotation\Route;
  9. class DefaultController extends AbstractController
  10. {
  11.     private $mailHandler;
  12.     public function __construct(
  13.         MailHandler $mailHandler
  14.     ) {
  15.         $this->mailHandler $mailHandler;
  16.     }
  17.     /**
  18.      * @Route("/", name="default")
  19.      */
  20.     public function index(): Response
  21.     {
  22.         return $this->render('default/index.html.twig');
  23.     }
  24.     /**
  25.      * @return Response
  26.      *
  27.      * @Route("/about", name="about")
  28.      */
  29.     public function about(): Response
  30.     {
  31.         return $this->render('default/about.html.twig');
  32.     }
  33.     /**
  34.      * @param Request $request
  35.      * @return Response
  36.      *
  37.      * @Route("/contact", name="contact")
  38.      */
  39.     public function contact(Request $request): Response
  40.     {
  41.         $form $this->createForm(ContactUsType::class);
  42.         $form->handleRequest($request);
  43.         if ($form->isSubmitted() && $form->isValid()) {
  44.             $this->mailHandler->sendContactUs(
  45.                 $form->get('name')->getData(),
  46.                 $form->get('email')->getData(),
  47.                 $form->get('subject')->getData(),
  48.                 $form->get('message')->getData(),
  49.             );
  50.             $this->addFlash("flash_success""Message successfully sent!");
  51.         }
  52.         return $this->render('default/contact.html.twig', [
  53.             'contactForm' => $form->createView(),
  54.         ]);
  55.     }
  56. }