Commit 80dde071 authored by Shakarim Sapa's avatar Shakarim Sapa

- Add new validation rule

parent c1ee8886
......@@ -81,6 +81,8 @@ class Bid extends \common\components\ActiveRecordModel
[['email'], 'required', 'on' => self::SCENARIO_SUBSCRIBE],
[['email'], 'checkUnique', 'on' => self::SCENARIO_SUBSCRIBE, 'message' => 'Вы уже подписаны на новости блога'],
[['text'], 'string'],
[['name'], 'string', 'max' => 100],
......@@ -91,13 +93,10 @@ class Bid extends \common\components\ActiveRecordModel
];
}
public function beforeSave($insert){
if (!parent::beforeSave($insert))
return false;
if (!is_null($this->email)) {
if (Bid::find()->where(['email' => $this->email])->exists()===true) {
$this->addError('email', 'Вы уже подписаны на новости блога');
public function checkUnique($attribute, $params){
if (!is_null($this->$attribute)) {
if (Bid::find()->where([$attribute => $this->$attribute])->exists()===true) {
$this->addError($attribute, $params['message']);
return false;
}
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment