diff --git a/config/sfCmsPluginConfiguration.class.php b/config/sfCmsPluginConfiguration.class.php index 4ff232b..5fd3bee 100644 --- a/config/sfCmsPluginConfiguration.class.php +++ b/config/sfCmsPluginConfiguration.class.php @@ -16,8 +16,11 @@ class sfCmsPluginConfiguration extends sfPluginConfiguration public function initialize() { $this->dispatcher->connect('routing.load_configuration', array($this, 'listenToLoadRouting')); - sfConfig::set('sf_error_404_module', 'front'); + sfConfig::set('sf_error_404_module', 'sfCms'); sfConfig::set('sf_error_404_action', 'error404'); + if (!sfConfig::get('app_sf_cms_contact')) { + throw new sfException('Missing required parameter "app_sf_cms_contact".'); + } } public function listenToLoadRouting(sfEvent $event) diff --git a/i18n/sf_cms.fr.xml b/i18n/sf_cms.fr.xml index 6b90803..2af6251 100644 --- a/i18n/sf_cms.fr.xml +++ b/i18n/sf_cms.fr.xml @@ -28,6 +28,22 @@ Back Retour + + Form has errors. + Le formulaire comporte des erreurs. + + + New contact message + Nouveau message de contact + + + Visit website + Aller sur le site + + + Message has been successfully sent. + Le message a été correctement envoyé. + \ No newline at end of file diff --git a/lib/form/ContactForm.class.php b/lib/form/ContactForm.class.php index 07cb91b..92d8578 100644 --- a/lib/form/ContactForm.class.php +++ b/lib/form/ContactForm.class.php @@ -16,14 +16,14 @@ public function configure() $this->setWidgets(array( 'name' => new sfWidgetFormInputText(), 'email' => new sfWidgetFormInputText(), - 'website' => new sfWidgetFormInputText(), 'message' => new sfWidgetFormTextarea() )); $this->setValidators(array( 'name' => new sfValidatorString(), 'email' => new sfValidatorEmail(), - 'website' => new sfValidatorUrl(array('required' => false)), 'message' => new sfValidatorString() )); + $this->widgetSchema->setNameFormat('contact[%s]'); + $this->errorSchema = new sfValidatorErrorSchema($this->validatorSchema); } } diff --git a/modules/gabarits/lib/PluginGabaritsComponents.class.php b/modules/gabarits/lib/PluginGabaritsComponents.class.php index 3f50494..d8fa68f 100644 --- a/modules/gabarits/lib/PluginGabaritsComponents.class.php +++ b/modules/gabarits/lib/PluginGabaritsComponents.class.php @@ -14,23 +14,43 @@ public function executeContact(sfWebRequest $request) { $this->form = new ContactForm(); if ($request->isMethod('post')) { - die("
".print_r($request->getParameter($this->form->getName(), array()), true)."
"); + $this->form->bind($request->getParameter($this->form->getName(), array())); + if ($this->form->isValid()) { + $this->getContext()->getConfiguration()->loadHelpers('Partial'); + $message = $this->getMailer()->compose( + array($this->form->getValue('email') => $this->form->getValue('name')), + sfConfig::get('app_sf_cms_contact'), + $this->getContext()->getI18N()->__('New contact message', array(), 'sf_cms'), + get_partial('sfCms/mail', array( + 'title' => $this->getContext()->getI18N()->__('New contact message', array(), 'sf_cms'), + 'message' => $this->form->getValue('message') + )) + )->setContentType('text/html'); + $this->getMailer()->send($message); + $this->getUser()->setFlash('notice', $this->getContext()->getI18N()->__('Message has been successfully sent.', array(), 'sf_cms')); + } else { + $this->getUser()->setFlash('error', $this->getContext()->getI18N()->__('Form has errors.', array(), 'sf_cms'), false); + } } } public function executeDefault(sfWebRequest $request) { + } public function executeError(sfWebRequest $request) { + } public function executeHomepage(sfWebRequest $request) { + } public function executeSitemap(sfWebRequest $request) { + } } diff --git a/modules/gabarits/templates/_contact.php b/modules/gabarits/templates/_contact.php index cfe9e48..0b5db78 100644 --- a/modules/gabarits/templates/_contact.php +++ b/modules/gabarits/templates/_contact.php @@ -1,3 +1,11 @@ +isMethod('post') && $form->isValid()): ?> + + + @@ -14,18 +22,16 @@

getRaw('page')->getTitle() ?>

getRaw('page')->getContents() ?> -
" method="post"> +
renderHiddenFields() ?> hasGlobalErrors()): ?> renderGlobalErrors() ?> - + renderLabel() ?> render() ?> renderLabel() ?> render() ?> - renderLabel() ?> - render() ?> renderLabel() ?> render() ?> diff --git a/modules/sfCms/lib/PluginSfCmsActions.class.php b/modules/sfCms/lib/PluginSfCmsActions.class.php index 73781ac..81d9ecf 100644 --- a/modules/sfCms/lib/PluginSfCmsActions.class.php +++ b/modules/sfCms/lib/PluginSfCmsActions.class.php @@ -23,6 +23,7 @@ public function executeSitemap(sfWebRequest $request) $query = ArticleTable::getInstance()->createQuery() ->whereNotIn('slug', Article::getSystemSlugs()) ->andWhere('content_type = ?', Article::ARTICLE); + $this->renderText($text); $this->articles = ArticleTable::getInstance()->findAllPublished("now", "started_at DESC", null, $query); } diff --git a/modules/sfCms/templates/_mail.php b/modules/sfCms/templates/_mail.php new file mode 100644 index 0000000..d2d93e3 --- /dev/null +++ b/modules/sfCms/templates/_mail.php @@ -0,0 +1,29 @@ + + + + <?php echo $title ?> + + + + + + + + + + + + + + + +
+

+
+ +
+ © -
+ +
+ + \ No newline at end of file