Content Validation
Validation rules in Speck are generally creating using attributes of the cf_spProperty tag when creating a content type. All property types in Speck share a number of standard attributes related to validation (e.g. whether a property value is required), and for many property types, these built in attributes are sufficient. However, custom validations for property types can be created by simply creating a validateValue method when creating the property type. Some of the property types included with Speck have additional validation related attribtues (e.g. the match attribute of the Text property type), that are handled using a custom validateValue method for the property type.
When content items are validated, Speck loops over each property value, runs any standard validations and then calls the validateValue method if one exists for the property type. Once all property values have been validated, it then looks for a validate method for the content type and calls that if it exists. The validate method for the content type can be used to validate content where the validation rules available via the various properties of the content type are not sufficient. Typically, this is only the case when you need to validate the values of multiple properties together, because the validation rules set using the cf_spProperty tag normally apply to individual property values. For example, you could write a validate method to check that any one of three properties of a content item has a value, without requiring that all three have values.
Most of the time, you won't need to write any custom validation methods because the standard validation attributes for property types and the custom validation attributes for some built in property types will cover most bases. If you do need to write custom validation methods, there's really only one thing to remember - both the validateValue method for property types and the validate method for content types should append any error messages to the lErrors variable in local/variables scope. Speck takes care of copying this back to the caller and the standard Speck admin forms will display these errors to the user.
Note: using a list to store error messages was probably not
the smartest thing to do, and at some point we'll add an option
to append errors using a function that will store the errors in an
array. In the meantime, if you need to output a comma within an
error message, remember to html escape it (i.e. replace , with
,). This really sucks, but we know it sucks and we will
sort it out as soon as we get a chance.