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';
|
||||
}
|
||||
}
|
||||
@@ -28,7 +28,8 @@ INSERT INTO `config` (`name`, `value`, `secured`, `hidden`, `created_at`, `updat
|
||||
('thelia_customer_remember_me_cookie_name', 'tcrmcn', 0, 0, NOW(), NOW()),
|
||||
('thelia_customer_remember_me_cookie_expiration', 31536000, 0, 0, NOW(), NOW()),
|
||||
('session_config.handlers', 'Symfony\\Component\\HttpFoundation\\Session\\Storage\\Handler\\NativeFileSessionHandler', 0, 0, NOW(), NOW()),
|
||||
('company_name','', 0, 0, NOW(), NOW())
|
||||
('company_name','', 0, 0, NOW(), NOW()),
|
||||
('contact_email','', 0, 0, NOW(), NOW())
|
||||
;
|
||||
|
||||
|
||||
|
||||
@@ -50,6 +50,7 @@
|
||||
|
||||
// Form Register
|
||||
#form-address,
|
||||
#form-contact,
|
||||
#form-register {
|
||||
.panel-body {
|
||||
.control-label { .make-sm-column(3); }
|
||||
|
||||
15
templates/default/contact-success.html
Normal file
15
templates/default/contact-success.html
Normal file
@@ -0,0 +1,15 @@
|
||||
{extends file="layout.tpl"}
|
||||
|
||||
{* Breadcrumb *}
|
||||
{block name='no-return-functions' append}
|
||||
{$breadcrumbs = [['title' => {intl l="Thanks !"}, 'url'=>{url path="/contact/success"}]]}
|
||||
{/block}
|
||||
|
||||
{block name="main-content"}
|
||||
<div class="main">
|
||||
<article class="col-main" role="main" aria-labelledby="main-label">
|
||||
<h1 id="main-label" class="page-header">{intl l="Thanks !"}</h1>
|
||||
<p>{intl l="Thanks for your message, we will contact as soon as possible"}</p>
|
||||
</article>
|
||||
</div>
|
||||
{/block}
|
||||
@@ -1,5 +1,105 @@
|
||||
{extends file="layout.tpl"}
|
||||
|
||||
{block name="main-content"}
|
||||
{* Breadcrumb *}
|
||||
{block name='no-return-functions' append}
|
||||
{$breadcrumbs = [['title' => {intl l="Contact us"}, 'url'=>{url path="/contact"}]]}
|
||||
{/block}
|
||||
|
||||
{block name="main-content"}
|
||||
<div class="main">
|
||||
<article class="col-main" role="main" aria-labelledby="main-label">
|
||||
<h1 id="main-label" class="page-header">{intl l="Contact us"}</h1>
|
||||
|
||||
{form name="thelia.contact"}
|
||||
<form id="form-contact" class="form-horizontal" action="{url path="/contact"}" method="post" role="form">
|
||||
{form_hidden_fields form=$form}
|
||||
<fieldset id="contact-info" class="panel panel">
|
||||
<div class="panel-heading">
|
||||
1. {intl l="Personal Informations"}
|
||||
</div>
|
||||
<div class="panel-body">
|
||||
{form_field form=$form field="firstname"}
|
||||
<div class="form-group group-firstname {if $error}has-error{elseif $value != "" && !$error}has-success{/if}">
|
||||
<label class="control-label" for="{$label_attr.for}">{$label}{if $required} <span class="required">*</span>{/if}</label>
|
||||
<div class="control-input">
|
||||
<input type="text" name="{$name}" id="{$label_attr.for}" class="form-control" placeholder="John" value="{$value}" {if $required} aria-required="true" required{/if}{if !isset($error_focus) && $error} autofocus{/if}>
|
||||
{if $error }
|
||||
<span class="help-block"><i class="icon-remove"></i> {$message}</span>
|
||||
{assign var="error_focus" value="true"}
|
||||
{elseif $value != "" && !$error}
|
||||
<span class="help-block"><i class="icon-ok"></i></span>
|
||||
{/if}
|
||||
</div>
|
||||
</div><!--/.form-group-->
|
||||
{/form_field}
|
||||
{form_field form=$form field="lastname"}
|
||||
<div class="form-group group-firstname {if $error}has-error{elseif $value != "" && !$error}has-success{/if}">
|
||||
<label class="control-label" for="{$label_attr.for}">{$label}{if $required} <span class="required">*</span>{/if}</label>
|
||||
<div class="control-input">
|
||||
<input type="text" name="{$name}" id="{$label_attr.for}" class="form-control" placeholder="John" value="{$value}" {if $required} aria-required="true" required{/if}{if !isset($error_focus) && $error} autofocus{/if}>
|
||||
{if $error }
|
||||
<span class="help-block"><i class="icon-remove"></i> {$message}</span>
|
||||
{assign var="error_focus" value="true"}
|
||||
{elseif $value != "" && !$error}
|
||||
<span class="help-block"><i class="icon-ok"></i></span>
|
||||
{/if}
|
||||
</div>
|
||||
</div><!--/.form-group-->
|
||||
{/form_field}
|
||||
{form_field form=$form field="email"}
|
||||
<div class="form-group group-firstname {if $error}has-error{elseif $value != "" && !$error}has-success{/if}">
|
||||
<label class="control-label" for="{$label_attr.for}">{$label}{if $required} <span class="required">*</span>{/if}</label>
|
||||
<div class="control-input">
|
||||
<input type="email" name="{$name}" id="{$label_attr.for}" class="form-control" placeholder="johndoe@domain.com" value="{$value}" {if $required} aria-required="true" required{/if}{if !isset($error_focus) && $error} autofocus{/if}>
|
||||
{if $error }
|
||||
<span class="help-block"><i class="icon-remove"></i> {$message}</span>
|
||||
{assign var="error_focus" value="true"}
|
||||
{elseif $value != "" && !$error}
|
||||
<span class="help-block"><i class="icon-ok"></i></span>
|
||||
{/if}
|
||||
</div>
|
||||
</div><!--/.form-group-->
|
||||
{/form_field}
|
||||
{form_field form=$form field="subject"}
|
||||
<div class="form-group group-firstname {if $error}has-error{elseif $value != "" && !$error}has-success{/if}">
|
||||
<label class="control-label" for="{$label_attr.for}">{$label}{if $required} <span class="required">*</span>{/if}</label>
|
||||
<div class="control-input">
|
||||
<input type="text" name="{$name}" id="{$label_attr.for}" class="form-control" placeholder="contact subject" value="{$value}" {if $required} aria-required="true" required{/if}{if !isset($error_focus) && $error} autofocus{/if}>
|
||||
{if $error }
|
||||
<span class="help-block"><i class="icon-remove"></i> {$message}</span>
|
||||
{assign var="error_focus" value="true"}
|
||||
{elseif $value != "" && !$error}
|
||||
<span class="help-block"><i class="icon-ok"></i></span>
|
||||
{/if}
|
||||
</div>
|
||||
</div><!--/.form-group-->
|
||||
{/form_field}
|
||||
{form_field form=$form field="message"}
|
||||
<div class="form-group group-firstname {if $error}has-error{elseif $value != "" && !$error}has-success{/if}">
|
||||
<label class="control-label" for="{$label_attr.for}">{$label}{if $required} <span class="required">*</span>{/if}</label>
|
||||
<div class="control-input">
|
||||
<textarea name="{$name}" id="{$label_attr.for}" class="form-control">
|
||||
{$value}
|
||||
</textarea>
|
||||
{if $error }
|
||||
<span class="help-block"><i class="icon-remove"></i> {$message}</span>
|
||||
{assign var="error_focus" value="true"}
|
||||
{elseif $value != "" && !$error}
|
||||
<span class="help-block"><i class="icon-ok"></i></span>
|
||||
{/if}
|
||||
</div>
|
||||
</div><!--/.form-group-->
|
||||
{/form_field}
|
||||
|
||||
<div class="form-group group-btn">
|
||||
<div class="control-btn">
|
||||
<button type="submit" class="btn btn-register">{intl l="Send"}</button>
|
||||
</div>
|
||||
</div><!--/.form-group-->
|
||||
</div>
|
||||
</fieldset>
|
||||
</form>
|
||||
{/form}
|
||||
</article>
|
||||
</div>
|
||||
{/block}
|
||||
Reference in New Issue
Block a user