finish contact process
This commit is contained in:
@@ -173,4 +173,14 @@
|
||||
<default key="_view">contact</default>
|
||||
</route>
|
||||
|
||||
<route id="contact.send" path="/contact" methods="post">
|
||||
<default key="_controller">Thelia\Controller\Front\ContactController::sendAction</default>
|
||||
<default key="_view">contact</default>
|
||||
</route>
|
||||
|
||||
<route id="contact.success" path="/contact/success">
|
||||
<default key="_controller">Thelia\Controller\Front\DefaultController::noAction</default>
|
||||
<default key="_view">contact-success</default>
|
||||
</route>
|
||||
|
||||
</routes>
|
||||
|
||||
@@ -22,6 +22,9 @@
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace Thelia\Controller\Front;
|
||||
use Thelia\Form\ContactForm;
|
||||
use Thelia\Form\Exception\FormValidationException;
|
||||
use Thelia\Model\ConfigQuery;
|
||||
|
||||
|
||||
/**
|
||||
@@ -31,5 +34,40 @@ namespace Thelia\Controller\Front;
|
||||
*/
|
||||
class ContactController extends BaseFrontController
|
||||
{
|
||||
/**
|
||||
* send contact message
|
||||
*/
|
||||
public function sendAction()
|
||||
{
|
||||
$error_message = false;
|
||||
$contactForm = new ContactForm($this->getRequest());
|
||||
|
||||
try {
|
||||
$form = $this->validateForm($contactForm);
|
||||
|
||||
$message = \Swift_Message::newInstance($form->get('subject')->getData())
|
||||
->addFrom($form->get('email')->getData(), $form->get('firstname')->getData().' '.$form->get('lastname')->getData())
|
||||
->addTo(ConfigQuery::read('contact_email'), ConfigQuery::read('company_name'))
|
||||
->setBody($form->get('message')->getData())
|
||||
;
|
||||
|
||||
$this->getMailer()->send($message);
|
||||
|
||||
} catch(FormValidationException $e) {
|
||||
$error_message = $e->getMessage();
|
||||
}
|
||||
|
||||
if ($error_message !== false) {
|
||||
\Thelia\Log\Tlog::getInstance()->error(sprintf("Error during customer creation process : %s", $error_message));
|
||||
|
||||
$contactForm->setErrorMessage($error_message);
|
||||
|
||||
$this->getParserContext()
|
||||
->addForm($contactForm)
|
||||
->setGeneralError($error_message)
|
||||
;
|
||||
} else {
|
||||
$this->redirectToRoute('contact.success');
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -60,7 +60,7 @@ class ContactForm extends BaseForm
|
||||
{
|
||||
$this->formBuilder
|
||||
->add('firstname', 'text', array(
|
||||
'constraint' => array(
|
||||
'constraints' => array(
|
||||
new NotBlank()
|
||||
),
|
||||
'label' => Translator::getInstance()->trans('firstname'),
|
||||
@@ -69,7 +69,7 @@ class ContactForm extends BaseForm
|
||||
)
|
||||
))
|
||||
->add('lastname', 'text', array(
|
||||
'constraint' => array(
|
||||
'constraints' => array(
|
||||
new NotBlank()
|
||||
),
|
||||
'label' => Translator::getInstance()->trans('lastname'),
|
||||
@@ -78,7 +78,7 @@ class ContactForm extends BaseForm
|
||||
)
|
||||
))
|
||||
->add('email', 'email', array(
|
||||
'constraint' => array(
|
||||
'constraints' => array(
|
||||
new NotBlank(),
|
||||
new Email()
|
||||
),
|
||||
@@ -88,7 +88,7 @@ class ContactForm extends BaseForm
|
||||
)
|
||||
))
|
||||
->add('subject', 'text', array(
|
||||
'constraint' => array(
|
||||
'constraints' => array(
|
||||
new NotBlank()
|
||||
),
|
||||
'label' => Translator::getInstance()->trans('subject'),
|
||||
@@ -97,7 +97,7 @@ class ContactForm extends BaseForm
|
||||
)
|
||||
))
|
||||
->add('message', 'text', array(
|
||||
'constraint' => array(
|
||||
'constraints' => array(
|
||||
new NotBlank()
|
||||
),
|
||||
'label' => Translator::getInstance()->trans('message'),
|
||||
@@ -114,6 +114,6 @@ class ContactForm extends BaseForm
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return 'thelia.contact';
|
||||
return 'thelia_contact';
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user