Commit f6303c6a2805d76b08cad352b9076c092f81a73c
1 parent
a41b32a4
Добавлено:
1) Фильтры для инпут полей 2) 5-секундная блокировка кнопки Submit после отправки сообщения Изменено название Форма (на рус/укр) поле тема ==> поле телефон
Showing
5 changed files
with
210 additions
and
148 deletions
Show diff stats
common/messages/ru/app.php
common/messages/ua/app.php
common/models/Feedback.php
1 | 1 | <?php |
2 | - | |
3 | - namespace common\models; | |
4 | - | |
5 | - /** | |
6 | - * User: timur | |
7 | - * Date: 31.01.18 | |
8 | - * Time: 10:56 | |
9 | - */ | |
10 | - | |
11 | - use artbox\core\models\Feedback as ArtboxFeedback; | |
12 | - | |
13 | - /** | |
14 | - * Class Feedback | |
15 | - * | |
16 | - * @property string $topic | |
17 | - * @property string $calc_json_info | |
18 | - * @package common\models | |
19 | - */ | |
20 | - class Feedback extends ArtboxFeedback | |
2 | + | |
3 | +namespace common\models; | |
4 | + | |
5 | +/** | |
6 | + * User: timur | |
7 | + * Date: 31.01.18 | |
8 | + * Time: 10:56 | |
9 | + */ | |
10 | + | |
11 | +use artbox\core\models\Feedback as ArtboxFeedback; | |
12 | + | |
13 | +/** | |
14 | + * Class Feedback | |
15 | + * | |
16 | + * @property string $topic | |
17 | + * @property string $calc_json_info | |
18 | + * @package common\models | |
19 | + */ | |
20 | +class Feedback extends ArtboxFeedback | |
21 | +{ | |
22 | + | |
23 | + const SCENARIO_CALCULATOR = 'calculator'; | |
24 | + const calculator_attributes = [ | |
25 | + 'adress', | |
26 | + 'module_install_angle', | |
27 | + 'latitude', | |
28 | + 'longitude', | |
29 | + 'south_deviation', | |
30 | + 'power_station_type', | |
31 | + 'area', | |
32 | + 'power', | |
33 | + 'budget', | |
34 | + 'auth_day', | |
35 | + 'auth_month', | |
36 | + 'auth_pwr_all', | |
37 | + 'auth_pwr_days', | |
38 | + ]; | |
39 | + | |
40 | + const translate_attributes = [ | |
41 | + 'adress' => "Адрес", | |
42 | + 'module_install_angle' => "Угол установки фотомодулей", | |
43 | + 'latitude' => "Широта", | |
44 | + 'longitude' => "Долгота", | |
45 | + 'south_deviation' => "Отклонение от юга", | |
46 | + 'power_station_type' => "Тип станции", | |
47 | + 'area' => "Площадь", | |
48 | + 'power' => "Мощность", | |
49 | + 'budget' => "Бюджет", | |
50 | + 'auth_day' => "Суточное потребление в кВт*ч", | |
51 | + 'auth_month' => "Месячное потребление в кВт*ч", | |
52 | + 'auth_pwr_all' => "Мощность всех потребителей потребление в кВт*ч", | |
53 | + 'auth_pwr_days' => "Суток автономности", | |
54 | + ]; | |
55 | + | |
56 | + public $attributeValues = []; | |
57 | + | |
58 | + public function __set($name, $value) | |
21 | 59 | { |
22 | - | |
23 | - const SCENARIO_CALCULATOR = 'calculator'; | |
24 | - const calculator_attributes = [ | |
25 | - 'adress', | |
26 | - 'module_install_angle', | |
27 | - 'latitude', | |
28 | - 'longitude', | |
29 | - 'south_deviation', | |
30 | - 'power_station_type', | |
31 | - 'area', | |
32 | - 'power', | |
33 | - 'budget', | |
34 | - 'auth_day', | |
35 | - 'auth_month', | |
36 | - 'auth_pwr_all', | |
37 | - 'auth_pwr_days', | |
38 | - ]; | |
39 | - | |
40 | - const translate_attributes = [ | |
41 | - 'adress' => "Адрес", | |
42 | - 'module_install_angle' => "Угол установки фотомодулей", | |
43 | - 'latitude' => "Широта", | |
44 | - 'longitude' => "Долгота", | |
45 | - 'south_deviation' => "Отклонение от юга", | |
46 | - 'power_station_type' => "Тип станции", | |
47 | - 'area' => "Площадь", | |
48 | - 'power' => "Мощность", | |
49 | - 'budget' => "Бюджет", | |
50 | - 'auth_day' => "Суточное потребление в кВт*ч", | |
51 | - 'auth_month' => "Месячное потребление в кВт*ч", | |
52 | - 'auth_pwr_all' => "Мощность всех потребителей потребление в кВт*ч", | |
53 | - 'auth_pwr_days' => "Суток автономности", | |
54 | - ]; | |
55 | - | |
56 | - public $attributeValues = []; | |
57 | - | |
58 | - public function __set($name, $value) | |
59 | - { | |
60 | - if (in_array($name, self::calculator_attributes)) { | |
61 | - if (isset($value) && !empty($value)) { | |
62 | - $this->attributeValues[ $name ] = $value; | |
63 | - } | |
64 | - } else { | |
65 | - parent::__set($name, $value); | |
66 | - } | |
67 | - } | |
68 | - | |
69 | - public function __get($name) | |
70 | - { | |
71 | - if (in_array($name, self::calculator_attributes)) { | |
72 | - return $this->attributeValues[ $name ]??''; | |
73 | - } else { | |
74 | - return parent::__get($name); | |
60 | + if (in_array($name, self::calculator_attributes)) { | |
61 | + if (isset($value) && !empty($value)) { | |
62 | + $this->attributeValues[ $name ] = $value; | |
75 | 63 | } |
64 | + } else { | |
65 | + parent::__set($name, $value); | |
76 | 66 | } |
77 | - | |
78 | - public function getCalculatorAttributes() | |
79 | - { | |
80 | - return $this->attributeValues; | |
67 | + } | |
68 | + | |
69 | + public function __get($name) | |
70 | + { | |
71 | + if (in_array($name, self::calculator_attributes)) { | |
72 | + return $this->attributeValues[ $name ]??''; | |
73 | + } else { | |
74 | + return parent::__get($name); | |
81 | 75 | } |
82 | - | |
83 | - public function scenarios() | |
84 | - { | |
85 | - return array_merge( | |
86 | - parent::scenarios(), | |
87 | - [ | |
88 | - parent::SCENARIO_FEEDBACK => [ | |
89 | - 'name', | |
90 | - 'email', | |
91 | - 'phone', | |
92 | - 'message', | |
93 | - 'returnUrl', | |
94 | - 'topic', | |
95 | - ], | |
96 | - parent::SCENARIO_CALLBACK => [ | |
76 | + } | |
77 | + | |
78 | + public function getCalculatorAttributes() | |
79 | + { | |
80 | + return $this->attributeValues; | |
81 | + } | |
82 | + | |
83 | + public function scenarios() | |
84 | + { | |
85 | + return array_merge( | |
86 | + parent::scenarios(), | |
87 | + [ | |
88 | + parent::SCENARIO_FEEDBACK => [ | |
89 | + 'name', | |
90 | + 'email', | |
91 | + 'phone', | |
92 | + 'message', | |
93 | + 'returnUrl', | |
94 | + 'topic', | |
95 | + ], | |
96 | + parent::SCENARIO_CALLBACK => [ | |
97 | + 'name', | |
98 | + 'phone', | |
99 | + 'message', | |
100 | + 'returnUrl', | |
101 | + 'topic', | |
102 | + ], | |
103 | + self::SCENARIO_CALCULATOR => array_merge( | |
104 | + [ | |
97 | 105 | 'name', |
98 | 106 | 'phone', |
99 | - 'message', | |
107 | + 'email', | |
100 | 108 | 'returnUrl', |
101 | 109 | 'topic', |
110 | + 'calc_json_info', | |
102 | 111 | ], |
103 | - self::SCENARIO_CALCULATOR => array_merge( | |
104 | - [ | |
105 | - 'name', | |
106 | - 'phone', | |
107 | - 'email', | |
108 | - 'returnUrl', | |
109 | - 'topic', | |
110 | - 'calc_json_info', | |
111 | - ], | |
112 | - self::calculator_attributes | |
113 | - ), | |
114 | - ] | |
115 | - ); | |
116 | - } | |
117 | - | |
118 | - public function rules() | |
119 | - { | |
120 | - | |
121 | - return array_merge( | |
122 | - parent::rules(), | |
112 | + self::calculator_attributes | |
113 | + ), | |
114 | + ] | |
115 | + ); | |
116 | + } | |
117 | + | |
118 | + public function rules() | |
119 | + { | |
120 | + | |
121 | + return array_merge( | |
122 | + parent::rules(), | |
123 | + [ | |
123 | 124 | [ |
124 | 125 | [ |
125 | - [ | |
126 | - 'topic', | |
127 | - ], | |
128 | - 'required', | |
126 | + 'topic', | |
129 | 127 | ], |
128 | + 'required', | |
129 | + ], | |
130 | + [ | |
130 | 131 | [ |
131 | - [ | |
132 | - 'topic', | |
133 | - ], | |
134 | - 'string', | |
135 | - 'max' => 100, | |
132 | + 'topic', | |
136 | 133 | ], |
134 | + 'string', | |
135 | + 'max' => 100, | |
136 | + ], | |
137 | + [ | |
137 | 138 | [ |
138 | - [ | |
139 | - 'name', | |
140 | - 'phone', | |
141 | - 'email', | |
142 | - 'calc_json_info', | |
143 | - | |
144 | - 'adress', | |
145 | - 'module_install_angle', | |
146 | - ], | |
147 | - 'required', | |
148 | - 'on' => self::SCENARIO_CALCULATOR, | |
139 | + 'name', | |
140 | + 'phone', | |
141 | + 'email', | |
142 | + 'calc_json_info', | |
143 | + | |
144 | + 'adress', | |
145 | + 'module_install_angle', | |
149 | 146 | ], |
150 | - ] | |
151 | - ); | |
152 | - } | |
153 | - | |
154 | - public function setCalcJsonInfo() | |
155 | - { | |
156 | - $this->calc_json_info = json_encode($this->attributeValues); | |
157 | - } | |
158 | - | |
159 | - public function getCalcJsonInfo() | |
160 | - { | |
161 | - return json_decode($this->calc_json_info); | |
162 | - } | |
163 | - } | |
164 | 147 | \ No newline at end of file |
148 | + 'required', | |
149 | + 'on' => self::SCENARIO_CALCULATOR, | |
150 | + ], | |
151 | + [ | |
152 | + ['message'],'required','message'=>'Поле сообщение обязательное для заполнения'], | |
153 | + [ | |
154 | + ['message'],'string','min'=>10], | |
155 | + [['phone'],'string','length'=>[17,17],'message'=>'Введите данные в форму согласно заданному шаблону: +38(132) 456 78 89'], | |
156 | + [['phone'],'match','pattern'=>'/\+3?8?\(?([\d]{3}([ .-]?))\)?([ .-]?)([\d]{3}([ .-]?))\2([\d]{2}([ .-]?))([\d]{2}([ .-]?))/','message'=>'некорректный ввод поля. Значение должно иметь вид: +38(123) 456 78 79'], | |
157 | + | |
158 | + [['name','email'],'string','length'=>[5,25]], | |
159 | + [['name'],'match','pattern' => '/^[а-яА-ЯёЁa-zA-Z\-\s]+$/','message'=> \Yii::t('app', 'Имя может состоять только из | |
160 | + английский или латинских символов')], | |
161 | + [['email'],'email'], | |
162 | + | |
163 | + ] | |
164 | + ); | |
165 | + } | |
166 | + | |
167 | + public function setCalcJsonInfo() | |
168 | + { | |
169 | + $this->calc_json_info = json_encode($this->attributeValues); | |
170 | + } | |
171 | + | |
172 | + public function getCalcJsonInfo() | |
173 | + { | |
174 | + return json_decode($this->calc_json_info); | |
175 | + } | |
176 | +} | |
165 | 177 | \ No newline at end of file | ... | ... |
frontend/assets/AppAsset.php
frontend/web/js/script.js
1 | 1 | $( |
2 | 2 | function() { |
3 | + phoneMask('input[name="Feedback[phone]"]'); | |
4 | + | |
3 | 5 | |
4 | 6 | /** |
5 | 7 | * Modal form submit code |
... | ... | @@ -142,5 +144,52 @@ $( |
142 | 144 | // $("#feedback-form")['0'].reset(); |
143 | 145 | $(".send-form").attr('id', 'callback'); |
144 | 146 | }); |
147 | + | |
148 | + | |
149 | + function phoneMask(maskCssSelector) { | |
150 | + var phoneInput = maskCssSelector; | |
151 | + | |
152 | + if($('body').find(phoneInput).length>0){ | |
153 | + $(phoneInput).mask('+38(000)000-00-00',{placeholder:'+38(000)000-00-00'}); | |
154 | + $(phoneInput).focus(function () { | |
155 | + if(($(this).val())== '') {$(this).val('+38(0')} | |
156 | + }); | |
157 | + $(phoneInput).focusout(function () { | |
158 | + var phoneVal = $(this).val() | |
159 | + //if(phoneVal == '+38(0' || phoneVal == '+38(' || phoneVal == '+38' || phoneVal == '+3' || phoneVal == '+') {$(this).val('')} | |
160 | + if(phoneVal.length <17) {$(this).val('')} | |
161 | + }); | |
162 | + } | |
163 | + } | |
164 | + | |
165 | + | |
166 | + /** | |
167 | + * Блокирую кнопку сабмита после нажатия на 5 сек | |
168 | + */ | |
169 | + $('button[type="Submit"]').on('click',function () { | |
170 | + var $this = $(this); | |
171 | + $this.attr('disabled', true); | |
172 | + setTimeout(function() { | |
173 | + $this.attr('disabled', false); | |
174 | + }, 5000); | |
175 | + }); | |
176 | + | |
177 | + | |
178 | + | |
179 | + | |
180 | + | |
181 | + | |
182 | + | |
183 | + | |
145 | 184 | } |
185 | + | |
186 | + | |
187 | + | |
188 | + | |
189 | + | |
190 | + | |
191 | + | |
192 | + | |
193 | + | |
194 | + | |
146 | 195 | ); |
147 | 196 | \ No newline at end of file | ... | ... |