public function afterValidate() { $one_of = array('site_id', 'subspecialty_id', 'firm_id'); $found = false; foreach ($one_of as $attr) { if ($this->{$attr}) { $found = true; } } if (!$found) { $this->addError(null, 'At least one of ' . implode(', ', array_map(function ($attr) { return $this->getAttributeLabel($attr); }, $one_of)) . ' must be set.'); } parent::afterValidate(); }