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.

46 lines
1.3 KiB

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