At least one out of three inputs is needed

Hi,

Suppose I have three fields:

name

class

school

and I require at least one of them to be not empty. How do specify this in the model class?

Thanks.

You can always extend CValidator and create your own specific to your needs. (more elegant way to do it).

Otherwise, I suppose you could merge them in an array in your view, like:




Oneofthem['name']

Oneofthem['school']

Oneofthem['class']

and create a Oneofthem attribute in your model that will be required…

Of course, you should then assign each of these properties to your real ones before saving (model) and before representing (view).

Just a thought, haven’test it …

You can write a custom function for validate them.

Add a rule named oneOfThem, this will call a function:


public function oneOfThem()

{

	if ((!$this->name)&&(!$this->school)&&(!$this->class))

		$this->addError(...)

}

…or you can use this validator (atleastvalidator). It might be useful.