Commit 977f4921154cd962e7234215f050d81e73a3f7c1

Authored by Yarik
1 parent e67c95f9

Callback

frontend/controllers/SiteController.php
... ... @@ -13,6 +13,7 @@
13 13 use common\models\SignupForm;
14 14 use Yii;
15 15 use yii\base\InvalidParamException;
  16 + use yii\bootstrap\Html;
16 17 use yii\web\BadRequestHttpException;
17 18 use yii\web\Controller;
18 19 use yii\filters\VerbFilter;
... ... @@ -180,12 +181,46 @@
180 181 }
181 182 }
182 183  
  184 + public function actionCallback()
  185 + {
  186 + Yii::$app->response->format = Response::FORMAT_JSON;
  187 + $model = new Feedback(
  188 + [
  189 + 'scenario' => Feedback::SCENARIO_CALLBACK,
  190 + ]
  191 + );
  192 + if ($model->load(Yii::$app->request->post()) && $model->save()) {
  193 + \Yii::$app->session->setFlash(
  194 + 'success',
  195 + Html::tag(
  196 + 'div',
  197 + Html::tag(
  198 + 'h3',
  199 + \Yii::t('app', 'Обратный звонок')
  200 + ) . Html::tag(
  201 + 'p',
  202 + \Yii::t(
  203 + 'app',
  204 + 'Ваша заявка успешно отправлена. Мы свяжемся с Вами в ближайшее время.'
  205 + )
  206 + )
  207 + )
  208 + );
  209 + return $this->redirect($model->returnUrl ? : [ 'index' ]);
  210 + } else {
  211 + return [
  212 + 'success' => false,
  213 + 'error' => $model->errors,
  214 + ];
  215 + }
  216 + }
  217 +
183 218 public function actionLogin()
184 219 {
185 220 if (!\Yii::$app->user->isGuest) {
186 221 return $this->redirect([ 'index' ]);
187 222 }
188   -
  223 +
189 224 $loginForm = new LoginForm();
190 225 $signupForm = new SignupForm();
191 226 if ($loginForm->load(\Yii::$app->request->post()) && $loginForm->login()) {
... ... @@ -216,7 +251,7 @@
216 251 public function actionLogout()
217 252 {
218 253 \Yii::$app->user->logout();
219   -
  254 +
220 255 return $this->redirect([ 'index' ]);
221 256 }
222 257  
... ... @@ -231,7 +266,7 @@
231 266 if ($model->load(Yii::$app->request->post()) && $model->validate()) {
232 267 if ($model->sendEmail()) {
233 268 Yii::$app->session->setFlash('success', 'Check your email for further instructions.');
234   -
  269 +
235 270 return $this->redirect([ 'index' ]);
236 271 } else {
237 272 Yii::$app->session->setFlash(
... ... @@ -240,7 +275,7 @@
240 275 );
241 276 }
242 277 }
243   -
  278 +
244 279 return $this->render(
245 280 'requestPasswordResetToken',
246 281 [
... ... @@ -264,13 +299,13 @@
264 299 } catch (InvalidParamException $e) {
265 300 throw new BadRequestHttpException($e->getMessage());
266 301 }
267   -
  302 +
268 303 if ($model->load(Yii::$app->request->post()) && $model->validate() && $model->resetPassword()) {
269 304 Yii::$app->session->setFlash('success', 'New password saved.');
270   -
  305 +
271 306 return $this->redirect([ 'index' ]);
272 307 }
273   -
  308 +
274 309 return $this->render(
275 310 'resetPassword',
276 311 [
... ...
frontend/views/layouts/main.php
... ... @@ -19,6 +19,7 @@
19 19 use yii\base\Model;
20 20 use yii\bootstrap\ActiveForm;
21 21 use yii\bootstrap\Html;
  22 + use yii\helpers\Url;
22 23 use yii\web\View;
23 24 use yii\widgets\Breadcrumbs;
24 25  
... ... @@ -138,8 +139,8 @@ _________________________________________________________ -->
138 139 </div>
139 140 <div class="inline-block">
140 141 <span class="top-phone"><i class="fa fa-phone"></i>&ensp;<?php echo $settings->phone; ?></span>
141   - <a href="#" class="link-underline_dott">
142   - Обратный звонок
  142 + <a href="#" data-toggle="modal" data-target="#callback-modal" class="link-underline_dott">
  143 + <?php echo "Обратный звонок"; ?>
143 144 </a>
144 145 </div>
145 146 <div class="inline-block login">
... ... @@ -440,6 +441,74 @@ _________________________________________________________ --&gt;
440 441 ?>
441 442  
442 443 <!-- *** Breadcrumbs *** -->
  444 + <!-- *** FEEDBACK MODAL BEGIN *** -->
  445 + <?php
  446 + ?>
  447 +
  448 + <?php
  449 + $callback = new Feedback(
  450 + [
  451 + 'scenario' => Feedback::SCENARIO_CALLBACK,
  452 + 'returnUrl' => Url::current([], true),
  453 + ]
  454 + );
  455 + ?>
  456 + <div class="modal fade" id="callback-modal" tabindex="-1" role="dialog" aria-labelledby="Login" aria-hidden="true">
  457 + <div class="modal-dialog modal-sm">
  458 +
  459 + <div class="modal-content">
  460 + <div class="modal-header">
  461 + <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
  462 + <h4 class="modal-title callback" id="Login">Обратный звонок</h4>
  463 + </div>
  464 + <div class="modal-body">
  465 + <?php
  466 + $form = ActiveForm::begin(
  467 + [
  468 + 'action' => [ 'site/callback' ],
  469 + ]
  470 + );
  471 + echo $form->field($callback, 'returnUrl')
  472 + ->label(false)
  473 + ->hiddenInput();
  474 + echo $form->field($callback, 'name')
  475 + ->label(false)
  476 + ->textInput(
  477 + [
  478 + 'placeholder' => $callback->getAttributeLabel('name'),
  479 + ]
  480 + );
  481 + echo $form->field($callback, 'phone')
  482 + ->label(false)
  483 + ->textInput(
  484 + [
  485 + 'placeholder' => $callback->getAttributeLabel('phone'),
  486 + ]
  487 + );
  488 + echo Html::tag(
  489 + 'p',
  490 + Html::submitButton(
  491 + Html::icon(
  492 + 'sign-in',
  493 + [
  494 + 'prefix' => 'fa fa-',
  495 + ]
  496 + ) . \Yii::t('app', 'Отправить'),
  497 + [
  498 + 'class' => 'btn btn-template-main',
  499 + ]
  500 + ),
  501 + [
  502 + 'class' => 'text-center',
  503 + ]
  504 + );
  505 + $form::end();
  506 + ?>
  507 + </div>
  508 + </div>
  509 + </div>
  510 + </div>
  511 + <!-- *** FEEDBACK MODAL END *** -->
443 512 <?php
444 513 if (!$isHome) {
445 514 ?>
... ...