src\Controller\ContactController.php line 33

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4.  * Copyright (c) 2019. Dreamoov.
  5.  */
  6. namespace App\Controller;
  7. use App\Form\ContactType;
  8. use App\Models\Contact;
  9. use App\Service\EmailService;
  10. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  11. use Symfony\Component\HttpFoundation\Request;
  12. use Symfony\Component\Mailer\Exception\TransportExceptionInterface;
  13. use Symfony\Component\Mailer\MailerInterface;
  14. use Symfony\Component\Routing\Annotation\Route;
  15. /**
  16.  * Class ContactController.
  17.  *
  18.  * @Route("", name="contact_", options={"sitemap": true})
  19.  */
  20. class ContactController extends AbstractController
  21. {
  22.     /**
  23.      * @Route("/contact/", name="index")
  24.      *
  25.      * @param MailerInterface $mailer
  26.      *
  27.      * @return \Symfony\Component\HttpFoundation\Response
  28.      */
  29.     public function index(Request $requestEmailService $emailService)
  30.     {
  31.         $contact = new Contact();
  32.         $isSent false;
  33.         $form $this->createForm(ContactType::class, $contact, [
  34.             'action' => $this->generateUrl('contact_index'),
  35.             'method' => 'POST',
  36.         ]);
  37.         $form->handleRequest($request);
  38.         $resultMailer null;
  39.         if ($form->isSubmitted() && $form->isValid()) {
  40.             $isSent true;
  41.             $resultMailer true;
  42.             $emailService->sendMailToSauvegarde('Demande via le formulaire de contact pitaxes.ch''email/contact.html.twig', ['contact' => $contact]);
  43.             unset($contact$form);
  44.             $contact = new Contact();
  45.             $form $this->createForm(ContactType::class, $contact, [
  46.                 'action' => $this->generateUrl('contact_index'),
  47.                 'method' => 'POST',
  48.             ]);
  49.         }
  50.         return $this->render('contact/index.html.twig', [
  51.             'form' => $form->createView(),
  52.             'email_state' => $resultMailer,
  53.             'isSent' => $isSent,
  54.         ]);
  55.     }
  56. }