<?php
namespace App\Controller;
use App\Entity\ContactUs;
use App\Form\ContactType;
use Doctrine\Persistence\ManagerRegistry;
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-us", name="contact")
*/
public function index(Request $request, ManagerRegistry $registry): Response
{
$contact = new ContactUs();
$form = $this->createForm(ContactType::class, $contact, [
'attr' => [
'id' => 'contactForm',
'data-toggle' => 'validator',
'class' => 'shake',
],
]);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$entityManager = $registry->getManager();
$entityManager->flush();
return $this->redirectToRoute('contact', [], Response::HTTP_SEE_OTHER);
}
return $this->render('contact/index.html.twig', [
'controller_name' => 'ContactController',
'form' => $form->createView(),
]);
}
}