ValidateThis

A ColdFusion Validation Framework

Installation and Setup

Follow these simple steps to get started using the framework:

  1. Download the framework from validatethis.riaforge.org.
  2. Unzip the contents of the distribution into a folder on your machine. You can place this folder in your webroot, or place it elsewhere and create a mapping to it called ValidateThis.
  3. Create a Rules Definition File for a Business Object for which you want ValidateThis to generate validations. Take a look at the Sample Rules Definition File for an example.
  4. In your application code, create a ValidateThisConfig Struct, and then instantiate the ValidateThis.cfc facade object, passing in the struct, like so:
1
2
<cfset ValidateThisConfig = {definitionPath="/model/"} />
<cfset application.ValidateThis = createObject("component","ValidateThis.ValidateThis").init(ValidateThisConfig) />

Where:

  • definitionPath points to the folder into which you placed your Rules Definition File in step 3

More information on the keys that can be used in the ValidateThisConfig struct is available under Configuring the Framework.

You will now be able to call methods on the ValidateThis facade object to perform server-side and generate client-side validations.

For example, to perform server-side validations on an object, use the validate() method:

1
<cfset Result = application.ValidateThis.validate(myObject) />

To generate client-side validations, use the getValidationScript() method:

1
2
<cfset theScript = application.ValidateThis.getValidationScript(theObject=myObject) />
<cfhtmlhead text="#theScript#" />

Note that for many of the built-in validation types you’ll also have to include some initialization Javascript which is generated by calling the getInitializationScript() method:

1
2
<cfset initScript = application.ValidateThis.getInitializationScript() />
<cfhtmlhead text="#initScript#" />

Also note that the use of cfhtmlhead above is just a way of illustrating that you need to place the results of those method calls into your generated html in some way. You do not have to use cfhtmlhead to do that.

For more information on interacting with the ValidateThis.cfc facade object, see the section on Using the ValidateThis Facade Object.

Updated: