From c0781455cbdb41c868d26fd1090f53a755bd1eaa Mon Sep 17 00:00:00 2001 From: Manuel Raynaud Date: Mon, 21 Oct 2013 18:33:03 +0200 Subject: [PATCH] create contact form --- core/lib/Thelia/Config/Resources/config.xml | 2 + .../Thelia/Config/Resources/routing/front.xml | 5 + .../Controller/Front/ContactController.php | 35 ++++++ core/lib/Thelia/Form/ContactForm.php | 119 ++++++++++++++++++ templates/default/contact.html | 5 + 5 files changed, 166 insertions(+) create mode 100644 core/lib/Thelia/Controller/Front/ContactController.php create mode 100644 core/lib/Thelia/Form/ContactForm.php create mode 100644 templates/default/contact.html diff --git a/core/lib/Thelia/Config/Resources/config.xml b/core/lib/Thelia/Config/Resources/config.xml index baee3b2f4..eec3d71c8 100755 --- a/core/lib/Thelia/Config/Resources/config.xml +++ b/core/lib/Thelia/Config/Resources/config.xml @@ -142,6 +142,8 @@
+ + diff --git a/core/lib/Thelia/Config/Resources/routing/front.xml b/core/lib/Thelia/Config/Resources/routing/front.xml index 542a1a319..2235bdb0c 100755 --- a/core/lib/Thelia/Config/Resources/routing/front.xml +++ b/core/lib/Thelia/Config/Resources/routing/front.xml @@ -168,4 +168,9 @@ Thelia\Controller\Front\Mail::test + + Thelia\Controller\Front\DefaultController::noAction + contact + + diff --git a/core/lib/Thelia/Controller/Front/ContactController.php b/core/lib/Thelia/Controller/Front/ContactController.php new file mode 100644 index 000000000..a807f6351 --- /dev/null +++ b/core/lib/Thelia/Controller/Front/ContactController.php @@ -0,0 +1,35 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Thelia\Controller\Front; + + +/** + * Class ContactController + * @package Thelia\Controller\Front + * @author Manuel Raynaud + */ +class ContactController extends BaseFrontController +{ + +} \ No newline at end of file diff --git a/core/lib/Thelia/Form/ContactForm.php b/core/lib/Thelia/Form/ContactForm.php new file mode 100644 index 000000000..4ac94a2cd --- /dev/null +++ b/core/lib/Thelia/Form/ContactForm.php @@ -0,0 +1,119 @@ +. */ +/* */ +/*************************************************************************************/ + +namespace Thelia\Form; + +use Symfony\Component\Validator\Constraints\Email; +use Symfony\Component\Validator\Constraints\NotBlank; +use Thelia\Core\Translation\Translator; + + +/** + * Class ContactForm + * @package Thelia\Form + * @author Manuel Raynaud + */ +class ContactForm 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('firstname', 'text', array( + 'constraint' => array( + new NotBlank() + ), + 'label' => Translator::getInstance()->trans('firstname'), + 'label_attr' => array( + 'for' => 'firstname_contact' + ) + )) + ->add('lastname', 'text', array( + 'constraint' => array( + new NotBlank() + ), + 'label' => Translator::getInstance()->trans('lastname'), + 'label_attr' => array( + 'for' => 'lastname_contact' + ) + )) + ->add('email', 'email', array( + 'constraint' => array( + new NotBlank(), + new Email() + ), + 'label' => Translator::getInstance()->trans('email'), + 'label_attr' => array( + 'for' => 'email_contact' + ) + )) + ->add('subject', 'text', array( + 'constraint' => array( + new NotBlank() + ), + 'label' => Translator::getInstance()->trans('subject'), + 'label_attr' => array( + 'for' => 'subject_contact' + ) + )) + ->add('message', 'text', array( + 'constraint' => array( + new NotBlank() + ), + 'label' => Translator::getInstance()->trans('message'), + 'label_attr' => array( + 'for' => 'message_contact' + ) + + )) + ; + } + + /** + * @return string the name of you form. This name must be unique + */ + public function getName() + { + return 'thelia.contact'; + } +} \ No newline at end of file diff --git a/templates/default/contact.html b/templates/default/contact.html new file mode 100644 index 000000000..161ef58ab --- /dev/null +++ b/templates/default/contact.html @@ -0,0 +1,5 @@ +{extends file="layout.tpl"} + +{block name="main-content"} + +{/block} \ No newline at end of file