src/Controller/Front/BecomeAFounderController.php line 18

  1. <?php
  2. namespace App\Controller\Front;
  3. use App\Entity\Front\Contact;
  4. use App\Form\Front\ContactType;
  5. use App\Repository\Front\ContactRepository;
  6. use Symfony\Bridge\Twig\Mime\TemplatedEmail;
  7. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  8. use Symfony\Component\HttpFoundation\Request;
  9. use Symfony\Component\HttpFoundation\Response;
  10. use Symfony\Component\Mailer\MailerInterface;
  11. use Symfony\Component\Routing\Annotation\Route;
  12. class BecomeAFounderController extends AbstractController
  13. {
  14.     #[Route('/become-a-founder'name'app_front_become_a_founder')]
  15.     public function index(
  16.         Request $request,
  17.         ContactRepository $contactRepository,
  18.         MailerInterface $mailer
  19.     ): Response {
  20.         $contact = new Contact();
  21.         $form $this->createForm(ContactType::class, $contact);
  22.         $form->handleRequest($request);
  23.         if ($form->isSubmitted() && $form->isValid()) {
  24.             $contact->setCreatedAt(new \DateTimeImmutable());
  25.             $contact->setSource('app_front_become_a_founder');
  26.             $contactRepository->save($contacttrue);
  27.             $email = (new TemplatedEmail())
  28.             ->to('notgoingtospam@founders-agency.com')
  29.             ->from($contact->getEmail())
  30.             ->subject('Consulta desde el sitio web')
  31.             ->htmlTemplate('front/contact/mail_template.html.twig')
  32.             ->context(['contact' => $contact]);
  33.             $mailer->send($email);
  34.             return $this->redirectToRoute('app_front_become_a_founder_thankyou');
  35.         }
  36.             return $this->render('front/become_a_founder/index.html.twig', [
  37.             'controller_name' => 'BecomeAFounderController',
  38.             'form' => $form->createView(),
  39.             ]);
  40.     }
  41.     #[Route('/become-a-founder-thankyou'name'app_front_become_a_founder_thankyou'methods:["GET"])]
  42.     public function thankyou(): Response
  43.     {
  44.         return $this->render('front/become_a_founder/thankyou.html.twig', [
  45.         'controller_name' => 'ContactController',
  46.         ]);
  47.     }
  48. }