<?php
namespace App\Controller;
use App\Form\ContactUsType;
use App\Services\MailHandler;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
class DefaultController extends AbstractController
{
private $mailHandler;
public function __construct(
MailHandler $mailHandler
) {
$this->mailHandler = $mailHandler;
}
/**
* @Route("/", name="default")
*/
public function index(): Response
{
return $this->render('default/index.html.twig');
}
/**
* @return Response
*
* @Route("/about", name="about")
*/
public function about(): Response
{
return $this->render('default/about.html.twig');
}
/**
* @param Request $request
* @return Response
*
* @Route("/contact", name="contact")
*/
public function contact(Request $request): Response
{
$form = $this->createForm(ContactUsType::class);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$this->mailHandler->sendContactUs(
$form->get('name')->getData(),
$form->get('email')->getData(),
$form->get('subject')->getData(),
$form->get('message')->getData(),
);
$this->addFlash("flash_success", "Message successfully sent!");
}
return $this->render('default/contact.html.twig', [
'contactForm' => $form->createView(),
]);
}
}