src/Controller/Front/ContactController.php line 20

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Front;
  3. use App\Model\ContactDTO;
  4. use App\Services\MailService;
  5. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  6. use Symfony\Component\HttpFoundation\Request;
  7. use Symfony\Component\Routing\Annotation\Route;
  8. /**
  9.  * Class ContactController
  10.  * @package App\Controller\Front
  11.  */
  12. class ContactController extends AbstractController
  13. {
  14.     /**
  15.      * @Route("/contact", name="front_contact")
  16.      */
  17.     public function contact()
  18.     {
  19.         return $this->render('front/contact/contact.html.twig');
  20.     }
  21.     /**
  22.      * @Route("/submit-form/contact", name="front_submit_form_contact")
  23.      */
  24.     public function contactForm(Request $requestMailService $mailService)
  25.     {
  26.         if (!$request->get('firstname') || !$request->get('lastname') || !$request->get('email') ||
  27.             !$request->get('phone') || !$request->get('message')) {
  28.             return $this->json([
  29.                 'status' => 'error',
  30.             ]);
  31.         }
  32.         $contactDto = new ContactDTO();
  33.         $contactDto->setFirstname($request->get('firstname'));
  34.         $contactDto->setLastname($request->get('lastname'));
  35.         $contactDto->setEmail($request->get('email'));
  36.         $contactDto->setPhone($request->get('phone'));
  37.         $contactDto->setMessage($request->get('message'));
  38.         $mailService->sendMail($contactDtoMailService::MAILTO_CONTACT);
  39.         return $this->json([
  40.             'status' => 'ok'
  41.         ]);
  42.     }
  43. }