Validating Optional Feilds

I’m pretty new to Yii, studying by working through The Yii Book while also applying it’s lessons to my production work as I go.

My current challenge is how do I apply validation rules to optional fields?

In some cases those are the foreign keys for optional relationships so I want to apply ‘exists’ if a key is there but also accept no key.

Other cases are optional data which I want to validate if anything is entered but also accept nothing entered.

In both sets of cases I can see possibilities where I might want to prompt the user if no value is provided, just to be sure that’s what they really intend, but I’m happy to treat that as more advanced play & leave it for now.

Cheers & TIA

Pedro :)

'allowEmpty' => true,


Thanks :)

I think you’ve just shown me for my newbieness :\


array('fields', 'exist', 'allowEmpty' => true),