Но оно почему то не срабатывает, в чём загвоздка?
Идея проверить, что в форме по правилам забиты поля cat и cat2.
Код: Выделить всё
public function rules()
{
return [
[['cat', 'cat2'],'validateLocationCategory'],
......
];
Код: Выделить всё
public function validateLocationCategory()
{
$c1 = $this->cat;
$c2 = $this->cat2;
if (!is_null($c1) ){
if(intval($c1) == 0){
$this->addError($this->cat, 'Select cat1');
}
if (!is_null($c2) ){
$isC2Good = true;
$pieces = explode(".", $c2);
foreach ($pieces as $one){
if (intval($one) == 0){
$this->addError($this->cat2, 'Select cat2');
break;
}
}
unset($one);
}
}