From aabd05f17fe4200990d56fd6fd84dea10b778dd9 Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Tue, 22 Oct 2013 09:42:57 +0200 Subject: [PATCH] create form and controller for newsletter --- core/lib/Thelia/Config/Resources/config.xml | 1 + .../Controller/Front/NewsletterController.php | 52 +++++++++++++ core/lib/Thelia/Form/NewsletterForm.php | 75 +++++++++++++++++++ 3 files changed, 128 insertions(+) create mode 100644 core/lib/Thelia/Controller/Front/NewsletterController.php create mode 100644 core/lib/Thelia/Form/NewsletterForm.php diff --git a/core/lib/Thelia/Config/Resources/config.xml b/core/lib/Thelia/Config/Resources/config.xml index 4305851b1..493f9fbf8 100755 --- a/core/lib/Thelia/Config/Resources/config.xml +++ b/core/lib/Thelia/Config/Resources/config.xml @@ -147,6 +147,7 @@
+ diff --git a/core/lib/Thelia/Controller/Front/NewsletterController.php b/core/lib/Thelia/Controller/Front/NewsletterController.php new file mode 100644 index 000000000..a5778ad46 --- /dev/null +++ b/core/lib/Thelia/Controller/Front/NewsletterController.php @@ -0,0 +1,52 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Thelia\Controller\Front; +use Thelia\Form\Exception\FormValidationException; +use Thelia\Form\NewsletterForm; + + +/** + * Class NewsletterController + * @package Thelia\Controller\Front + * @author Manuel Raynaud + */ +class NewsletterController extends BaseFrontController +{ + + public function subscribeAction() + { + $error_message = false; + $newsletterForm = new NewsletterForm($this->getRequest()); + + try { + + $form = $this->validateForm($newsletterForm); + + + + } catch(FormValidationException $e) { + + } + } +} \ No newline at end of file diff --git a/core/lib/Thelia/Form/NewsletterForm.php b/core/lib/Thelia/Form/NewsletterForm.php new file mode 100644 index 000000000..2bfff496c --- /dev/null +++ b/core/lib/Thelia/Form/NewsletterForm.php @@ -0,0 +1,75 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Thelia\Form; +use Symfony\Component\Validator\Constraints\Email; +use Symfony\Component\Validator\Constraints\NotBlank; + + +/** + * Class NewsletterForm + * @package Thelia\Form + * @author Manuel Raynaud + */ +class NewsletterForm extends BaseForm +{ + + /** + * + * in this function you add all the fields you need for your Form. + * Form this you have to call add method on $this->formBuilder attribute : + * + * $this->formBuilder->add("name", "text") + * ->add("email", "email", array( + * "attr" => array( + * "class" => "field" + * ), + * "label" => "email", + * "constraints" => array( + * new \Symfony\Component\Validator\Constraints\NotBlank() + * ) + * ) + * ) + * ->add('age', 'integer'); + * + * @return null + */ + protected function buildForm() + { + $this->formBuilder + ->add('email', 'email', array( + 'constraints' => array( + new NotBlank(), + new Email() + ) + )); + } + + /** + * @return string the name of you form. This name must be unique + */ + public function getName() + { + return 'thelia_newsletter'; + } +} \ No newline at end of file