I would like to validate the length of a string. Validation should fail if the attribute has been set and the string is empty. I had to set allowEmpty => false for it to do that.
However, I also want validation to pass if the attribute is not present at all (if it wasn’t included in the form).
I figured that CStringValidator would let this pass since checking for the presence of an attribute should really be left up to the required validator.
Is there any way to do what I wanna do without writing a custom validator?
This requirement is actually rarely needed in reality. If you are using a text field to collect input for the attribute, then no matter user enters anything or not, the form will be posted back with that field.
Because this is so rare, you may consider writing a custom validation method to achieve this.