Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

update contact form

  • Loading branch information...
commit 6dad01c70d8e155942f8829ae5f89d5b3577202b 1 parent 68ea64b
@vincentchalamon authored
View
5 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)
View
16 i18n/sf_cms.fr.xml
@@ -28,6 +28,22 @@
<source>Back</source>
<target>Retour</target>
</trans-unit>
+ <trans-unit>
+ <source>Form has errors.</source>
+ <target>Le formulaire comporte des erreurs.</target>
+ </trans-unit>
+ <trans-unit>
+ <source>New contact message</source>
+ <target>Nouveau message de contact</target>
+ </trans-unit>
+ <trans-unit>
+ <source>Visit website</source>
+ <target>Aller sur le site</target>
+ </trans-unit>
+ <trans-unit>
+ <source>Message has been successfully sent.</source>
+ <target>Le message a été correctement envoyé.</target>
+ </trans-unit>
</body>
</file>
</xliff>
View
4 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);
}
}
View
22 modules/gabarits/lib/PluginGabaritsComponents.class.php
@@ -14,23 +14,43 @@ public function executeContact(sfWebRequest $request)
{
$this->form = new ContactForm();
if ($request->isMethod('post')) {
- die("<pre>".print_r($request->getParameter($this->form->getName(), array()), true)."</pre>");
+ $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)
{
+
}
}
View
14 modules/gabarits/templates/_contact.php
@@ -1,3 +1,11 @@
+<?php if ($sf_request->isMethod('post') && $form->isValid()): ?>
+ <script type="text/javascript">
+ <!--
+ window.location = "<?php echo url_for($page->getRouteName()) ?>";
+ //-->
+ </script>
+<?php endif ?>
+
<?php use_javascripts_for_form($form) ?>
<?php use_stylesheets_for_form($form) ?>
@@ -14,18 +22,16 @@
<h1><?php echo $sf_data->getRaw('page')->getTitle() ?></h1>
<?php echo $sf_data->getRaw('page')->getContents() ?>
-<form action="<?php echo url_for("@contact_form") ?>" method="post">
+<form method="post">
<fieldset>
<?php echo $form->renderHiddenFields() ?>
<?php if ($form->hasGlobalErrors()): ?>
<?php echo $form->renderGlobalErrors() ?>
- <?php endif; ?>
+ <?php endif ?>
<?php echo $form["name"]->renderLabel() ?>
<?php echo $form["name"]->render() ?>
<?php echo $form["email"]->renderLabel() ?>
<?php echo $form["email"]->render() ?>
- <?php echo $form["website"]->renderLabel() ?>
- <?php echo $form["website"]->render() ?>
<?php echo $form["message"]->renderLabel() ?>
<?php echo $form["message"]->render() ?>
<input type="submit" name="submit" value="<?php echo __('Send', array(), 'sf_cms') ?>" />
View
1  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);
}
View
29 modules/sfCms/templates/_mail.php
@@ -0,0 +1,29 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr" lang="fr">
+ <head>
+ <title><?php echo $title ?></title>
+ <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
+ </head>
+ <body style="font-family: Arial; font-size: 14px;">
+ <table cellpadding="0" cellspacing="0" width="600" style="margin: 0 auto; color: #666;">
+ <tbody>
+ <tr>
+ <td style="border-bottom: thin solid #ddd; padding-bottom: 10px; text-align: center;">
+ <h1 style="margin: 0; font-weight: normal; font-size: 1.8em;"><?php echo $title ?></h1>
+ </td>
+ </tr>
+ <tr>
+ <td style="text-align: justify; padding: 10px 0 20px 0;">
+ <?php echo $message ?>
+ </td>
+ </tr>
+ <tr>
+ <td style="border-top: thin solid #ddd; text-align: center; padding-top: 10px; font-size: 0.9em;">
+ &copy; <?php echo date('Y') ?> - <?php echo url_for('@homepage', true) ?><br />
+ <a href="<?php echo url_for('@homepage', true) ?>" style="color: #2294e1; text-decoration: none;"><?php echo __('Visit website', array(), 'sf_cms') ?></a>
+ </td>
+ </tr>
+ </tbody>
+ </table>
+ </body>
+</html>
Please sign in to comment.
Something went wrong with that request. Please try again.