<?php
namespace App\Controller;
use App\Entity\Subscriber;
use App\Entity\Subscription;
use App\Form\NewsletterType;
use App\Form\SubscriptionType;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Response;
use Boab\CmsBundle\Controller\BaseController;
use Psr\Log\LoggerInterface;
class SubscriptionController extends BaseController
{
public function signup(Request $request, LoggerInterface $logger)
{
$form = $this->createForm(SubscriptionType::class, new Subscription, [
"action" => $this->router->generate("app.subscription.signup"),
"method"=>"post"
]);
$form->handleRequest($request);
if($form->isSubmitted() && $form->isValid()){
$data = $form->getData();
try{
$this->save($data);
return new JsonResponse([
'status' => 'success',
'message' => 'Thank you for subscribing'
]);
}catch(\Exception $e){
$this->logger->error("error", ['exception'=>$e]);
}
}
$view = $this->viewManager->load("page/subscription.html.twig");
$view->form = $form->createView();
return $view;
}
}