<?php
namespace App\Controller\Front;
use App\Model\ContactDTO;
use App\Services\MailService;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Annotation\Route;
/**
* Class ContactController
* @package App\Controller\Front
*/
class ContactController extends AbstractController
{
/**
* @Route("/contact", name="front_contact")
*/
public function contact()
{
return $this->render('front/contact/contact.html.twig');
}
/**
* @Route("/submit-form/contact", name="front_submit_form_contact")
*/
public function contactForm(Request $request, MailService $mailService)
{
if (!$request->get('firstname') || !$request->get('lastname') || !$request->get('email') ||
!$request->get('phone') || !$request->get('message')) {
return $this->json([
'status' => 'error',
]);
}
$contactDto = new ContactDTO();
$contactDto->setFirstname($request->get('firstname'));
$contactDto->setLastname($request->get('lastname'));
$contactDto->setEmail($request->get('email'));
$contactDto->setPhone($request->get('phone'));
$contactDto->setMessage($request->get('message'));
$mailService->sendMail($contactDto, MailService::MAILTO_CONTACT);
return $this->json([
'status' => 'ok'
]);
}
}