Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Commit

Permalink
update contact form
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentchalamon committed Oct 7, 2012
1 parent 68ea64b commit 6dad01c
Show file tree
Hide file tree
Showing 7 changed files with 83 additions and 8 deletions.
5 changes: 4 additions & 1 deletion config/sfCmsPluginConfiguration.class.php
Expand Up @@ -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)
Expand Down
16 changes: 16 additions & 0 deletions i18n/sf_cms.fr.xml
Expand Up @@ -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>
4 changes: 2 additions & 2 deletions lib/form/ContactForm.class.php
Expand Up @@ -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);
}
}
22 changes: 21 additions & 1 deletion modules/gabarits/lib/PluginGabaritsComponents.class.php
Expand Up @@ -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)
{

}
}
14 changes: 10 additions & 4 deletions 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) ?>

Expand All @@ -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') ?>" />
Expand Down
1 change: 1 addition & 0 deletions modules/sfCms/lib/PluginSfCmsActions.class.php
Expand Up @@ -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);
}

Expand Down
29 changes: 29 additions & 0 deletions 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>

0 comments on commit 6dad01c

Please sign in to comment.