<?php
namespace App\Controller;
use App\Entity\Main\Contact;
use ContainerC2aw7aC\getMessenger_Transport_AsyncService;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Contracts\Translation\TranslatorInterface;
class ContactController extends AbstractController
{
/**
* @Route("/iletisim", name="contact", methods={"GET","POST"})
*/
public function index(Request $request, TranslatorInterface $translator, EntityManagerInterface $manager): Response
{
$errorMessage = null;
$successMessage = null;
$fullName = null;
$email = null;
$subject = null;
$message = null;
$content = null;
if ($request->getMethod() == 'POST') {
parse_str($request->getContent(), $content);
if (!isset($content['full_name']) || !$content['full_name']) {
$fullName = $translator->trans('THIS_VALUE_NOT_BE_BLANK');
}
if (!isset($content['email']) || !$content['email']) {
$email = $translator->trans('THIS_VALUE_NOT_BE_BLANK');
} else if (!is_numeric(strpos($content['email'], '@'))) {
$email = $translator->trans('THIS_VALUE_IS_NOT_CORRECT_EMAIL_ADDRESS');
}
if (!isset($content['subject']) || !$content['subject']) {
$subject = $translator->trans('THIS_VALUE_NOT_BE_BLANK');
}
if (!isset($content['message']) || !$content['message']) {
$message = $translator->trans('THIS_VALUE_NOT_BE_BLANK');
}
if (!$fullName && !$email && !$subject && !$message) {
$contact = new Contact();
$contact->setMessage($content['message'])
->setEmail($content['email'])
->setFullName($content['full_name'])
->setSubject($content['subject']);
$manager->persist($contact);
$manager->flush();
$successMessage = $translator->trans('YOUR_REQUEST_HAS_BEEN_SUCCESSFULLY_SUBMITTED');
$content = null;
} else {
$errorMessage = $translator->trans('CHECK_INFORMATION_AND_TRY_AGAIN');
}
}
return $this->render('contact/index.html.twig', [
'fullName' => $fullName,
'email' => $email,
'subject' => $subject,
'message' => $message,
'errorMessage' => $errorMessage,
'successMessage' => $successMessage,
'values' => $content,
]);
}
}