src/Controller/App/ContactController.php line 16

Open in your IDE?
  1. <?php
  2. namespace App\Controller\App;
  3. use App\Entity\App\Contact;
  4. use App\Form\App\ContactType;
  5. use Doctrine\ORM\EntityManagerInterface;
  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.     #[Route('/contact'name'contact_index')]
  13.     public function index(Request $requestEntityManagerInterface $entityManager): Response
  14.     {
  15.         $contact = new Contact();
  16.         $contactForm $this->createForm(ContactType::class, $contact);
  17.         $contactForm->handleRequest($request);
  18.         if ($contactForm->isSubmitted() && $contactForm->isValid()) {
  19.             $contact->setSendAt(new \DateTimeImmutable());
  20.             $contact->setSeen(false);
  21.             $contact->setActive(true);
  22.             $entityManager->persist($contact);
  23.             $entityManager->flush();
  24.             $this->addFlash('success''Votre message s\'est correctement envoyé');
  25.             return $this->redirectToRoute('contact_index');
  26.         }
  27.         return $this->render('app/home/contact.html.twig', [
  28.             'form' => $contactForm->createView(),
  29.         ]);
  30.     }
  31. }