<?php
namespace App\Controller\App;
use App\Entity\App\Contact;
use App\Form\App\ContactType;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
class ContactController extends AbstractController
{
#[Route('/contact', name: 'contact_index')]
public function index(Request $request, EntityManagerInterface $entityManager): Response
{
$contact = new Contact();
$contactForm = $this->createForm(ContactType::class, $contact);
$contactForm->handleRequest($request);
if ($contactForm->isSubmitted() && $contactForm->isValid()) {
$contact->setSendAt(new \DateTimeImmutable());
$contact->setSeen(false);
$contact->setActive(true);
$entityManager->persist($contact);
$entityManager->flush();
$this->addFlash('success', 'Votre message s\'est correctement envoyé');
return $this->redirectToRoute('contact_index');
}
return $this->render('app/home/contact.html.twig', [
'form' => $contactForm->createView(),
]);
}
}