I’m trying to use the required validator in a model. The situation is that I either need to collect a user’s country, or their zip code (or both) - one of those options must be supplied.
Is there an easy way to do this using the required validator as is? I dug through the documentation and didn’t get any ideas, but am a bit hesitant to open a new can of worms trying to figure out how to write and use my own validator.
Create a new validator class by just copying the original CRequiredValidator. Then add special class property for the other attribute(s) you want to check. Take a look at CCompareValidator (to see how other attributes get accessed). Should be easy to implement.
I guess the asterisk (*) on a required field is done by checking if the validator is an instance of CRequiredValidator. So you may use that as a parent class.