From ab86aa3202e1be45d8a3edd35e32d286e2d04d38 Mon Sep 17 00:00:00 2001 From: dozer111 Date: Fri, 27 Apr 2018 11:14:42 +0200 Subject: [PATCH] Валидация формы --- common/models/Feedback.php | 7 +++++-- frontend/controllers/SiteController.php | 10 +++++++--- frontend/views/site/contact.php | 50 +++++++++++++++++++++++++------------------------- frontend/views/site/individual.php | 11 ++++++++--- frontend/views/site/legal.php | 7 ++++++- 5 files changed, 51 insertions(+), 34 deletions(-) diff --git a/common/models/Feedback.php b/common/models/Feedback.php index dbd73a2..4164da6 100755 --- a/common/models/Feedback.php +++ b/common/models/Feedback.php @@ -118,6 +118,9 @@ class Feedback extends ArtboxFeedback { return array_merge( + #родительские правила перетирали мои изменения касательно правила required, + # поэтому я вынес все правила кроме required cюда для того ,чтобы не поломать логику в других местах + #parent::rules(), [ [ @@ -155,7 +158,7 @@ class Feedback extends ArtboxFeedback ], 'required', 'message'=>Yii::t('app','requiredField'), - 'on' => self::SCENARIO_DEFAULT, + 'on' => [self::SCENARIO_DEFAULT], ], [ [ @@ -193,7 +196,7 @@ class Feedback extends ArtboxFeedback [ ['name'], 'match', - 'pattern' => '/^[a-zA-Zа-яА-ЯёЁ\s\-]+$/u', + 'pattern' => '/^[a-zA-Zа-яієїґ\'А-ЯІЄЇҐёЁ\s\-]+$/u', 'message'=> \Yii::t('app', 'wrongName'), 'on'=>[self::SCENARIO_FEEDBACK,self::SCENARIO_DEFAULT] ], diff --git a/frontend/controllers/SiteController.php b/frontend/controllers/SiteController.php index fb7fc4e..ded9ab3 100755 --- a/frontend/controllers/SiteController.php +++ b/frontend/controllers/SiteController.php @@ -129,7 +129,7 @@ 12, 42, ]; - + $objects = Objectkb::find() ->with('lang.alias') ->where( @@ -182,8 +182,12 @@ public function actionFeedback() { + Yii::$app->response->format = Response::FORMAT_JSON; - + $test=[2,4,5,2,5]; + $test=json_decode($test); + die($test); + /** * @var Mailer $mailer */ @@ -191,11 +195,11 @@ $settings = Settings::getInstance(); if (empty(Yii::$app->request->post())) { + throw new BadRequestHttpException(); } else { $post = Yii::$app->request->post('Feedback'); - switch ($post[ 'topic' ]) { case Feedback::SCENARIO_FEEDBACK : $model = new Feedback([ 'scenario' => Feedback::SCENARIO_FEEDBACK ]); diff --git a/frontend/views/site/contact.php b/frontend/views/site/contact.php index 4a4eb24..a721b1d 100755 --- a/frontend/views/site/contact.php +++ b/frontend/views/site/contact.php @@ -1,10 +1,10 @@ get('seo'); - + $this->params['h1'] = \Yii::t('app', 'menu-contacts'); $this->params[ 'breadcrumbs' ][] = $this->params['h1']; - + $js = <<< JS window.lat = {$settings->lat}; window.lon = {$settings->lon}; JS; - + $this->registerJs($js, View::POS_END); ?>
- +
- +

- +
- +
- +
@@ -76,8 +76,8 @@ JS;
- - + +
phone )) { @@ -104,12 +104,12 @@ JS; } ?>
- + email )) { ?>
- +
@@ -132,13 +132,13 @@ JS; } ?>
- +
- +
- +
- +

@@ -161,7 +161,7 @@ JS; field($contact, 'name') ->textInput()->label(\Yii::t('app', 'formname')); ?>
- +
field($contact, 'email') ->textInput()->label('Email'); ?> @@ -178,7 +178,7 @@ JS; ] )->label(\Yii::t('app', 'formmess')); ?>
- +
'.\Yii::t('app', 'LeaveMessage'), @@ -186,7 +186,7 @@ JS; 'class' => 'btn btn-template-main', ] ) ?> - +
@@ -194,10 +194,10 @@ JS;
- + - - + +
diff --git a/frontend/views/site/individual.php b/frontend/views/site/individual.php index 89314ce..7901c5d 100755 --- a/frontend/views/site/individual.php +++ b/frontend/views/site/individual.php @@ -9,7 +9,7 @@ */ use artbox\core\components\SeoComponent; - use artbox\core\models\Feedback; + use common\models\Feedback; use common\models\Settings; use yii\helpers\Html; use yii\helpers\Url; @@ -61,7 +61,8 @@
-
+
@@ -167,7 +168,11 @@
- + +
diff --git a/frontend/views/site/legal.php b/frontend/views/site/legal.php index 4c14718..5225b78 100755 --- a/frontend/views/site/legal.php +++ b/frontend/views/site/legal.php @@ -416,7 +416,12 @@ $this->registerJs($js, View::POS_END);

- + +
-- libgit2 0.21.4