/
pashko
/
siec
Обзор
Документация
Войти
/
pashko
/
siec
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
common/models/CalculatorForm.php
63 строки
2 KB
Kokorin Pavel
copy past sta files
22 апр 2020, 11:01
22 апр 2020, 11:01
6fdb817
Код
Авторство
О чём код?
<?php namespace common\models; use yii\base\Model; use yii; class CalculatorForm extends Model { public $from; public $to; public $weight; public $volume; public $phone; public $email; public $errMessage = '"Телефон" или "Почта" не могут быть пустыми'; public $fullname; public $message; public function rules() { return [ [['from', 'to', 'weight', 'volume'], 'required'], /*[['weight'], 'number', 'min' => 0.001, 'max' => 20000], [['volume'], 'number', 'min' => 0.001, 'max' => 105],*/ [['volume', 'weight', 'message'], 'string'], //['phone', 'match', 'pattern' => '$^.7.\(\d{3}\).\d{3}.\d{2}.\d{2}$'], ['phone', 'required', 'whenClient' => "function(attribute, value) { return $('#calculatorform-email').val() == '' }", 'message' => $this->errMessage, 'when' => function ($model) {return empty($model->email);}], ['email', 'email', 'whenClient' => "function(attribute, value) { return $('#calculatorform-phone').val() == '' }"], ['email', 'required', 'whenClient' => "function(attribute, value) { return $('#calculatorform-phone').val() == '' }", 'message' => $this->errMessage, 'when' => function ($model) {return empty($model->phone);}], ]; } public function emailAndPhoneValidation($attribute, $params) { if(empty($this->email) and empty($this->phone)) { $this->addError($attribute, yii::t('app', 'Phone or email is required')); } } /** * @inheritdoc */ public function attributeLabels() { return [ 'from' => 'Откуда забрать', 'to' => 'Куда доставить', 'weight' => 'Вес, кг', 'volume' => 'Объем, м3', 'phone' => 'Телефон', 'email' => 'Почта', 'fullname' => 'Полное имя', 'message' => 'Сообщение' ]; } } ?>