LibrarySites.Banner

All About Validation with the Sitecore ASP.NET CMS

This blog post contains or links to all of the information that I could find about validation with the Sitecore ASP.NET CMS.

This blog post describes validation in CMS user interfaces such as the Content Editor. For validating data entered into forms on the published web sites, use standard ASP.NET validation techniques or those provided by the Sitecore Web Forms for Marketers (WFM) product.

The Client Configuration Cookbook on the Sitecore Developer Network (SDN) contains a great deal of information about data validation. Again I don't want to duplicate this existing information, but to summarize, you can use the validation infrastructure to enforce almost anything about your data - item naming rules, item locations, field values and other requirements. Brian Pedersen provides a quick overview of field validators in his blog post Using Sitecore Field Validators.

To maximize performance and conserve machine resources, rather than configuring validation to run interactively in the user interface (such as in the Quick Action Bar or the Validation Bar), you may instead want to configure some validators to fire when the user clicks the Validate command on the Review tab of the ribbon or when they attempt to transition the content to the next workflow state.

While it's still supported for legacy reasons, I think it's important not to use the simple validation provided by the simple Validation and ValidationText properties of field definition items), and to instead use the validation infrastructure described in the Client Configuration Cookbook. One problem with the legacy approach is that if the data is invalid, you can't save the item - it just keeps prompting you to correct the issue, which you can't always correct (for example, in the standard values of a data template, a date field may contain $now instead of a valid date).

Note that validators can also provide validation commands allowing the user to automatically correct data conditions.

For some examples validators, see the following blog posts:

For information about invoking validators programmatically, see Aaron Blake's Validate Sitecore Item Programmatically.

My blog post Sitecore CMS 6 4 Suppress Validation Rules describes how you can disable validation rules for individual items in Sitecore 6.4 and later.

The Sitecore 6 XHTML Validation and the Embed HTML Element blog post by Michael Edwards provides information about configuring XHTML validation to allow elements not allowed in XHTML, such as the <embed> element.

To some extent, Content Editor warnings provide functionality similar to validators. For more information about Content Editor warnings and the getContentEditorWarnings pipeline, see my blog post Important Pipelines in the Sitecore ASPNET CMS.

If you have additional information or know of additional resources about validation, please comment on this blog post.

More posts All About the Sitecore ASP.NET CMS.