You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

41 lines
1.2 KiB

7 years ago
<?php
namespace frontend\controllers;
use core\services\ContactService;
use Yii;
use yii\web\Controller;
use core\forms\ContactForm;
class ContactController extends Controller
{
public $layout = 'contacts';
private $service;
public function __construct($id, $module, ContactService $service, $config = [])
{
parent::__construct($id, $module, $config);
$this->service = $service;
}
public function actionIndex()
{
$form = new ContactForm();
if ($form->load(Yii::$app->request->post()) && $form->validate()) {
try {
$this->service->send($form);
Yii::$app->session->setFlash('success', Yii::t('main', 'Thank you for contacting us. We will respond to you as soon as possible.'));
return $this->goHome();
} catch (\Exception $e) {
Yii::$app->errorHandler->logException($e);
Yii::$app->session->setFlash('error', Yii::t('main', 'There was an error sending your message.'));
}
return $this->refresh();
}
return $this->render('index', [
'model' => $form,
]);
}
}