Home

Luis Majano edited this page Nov 30, 2015 · 13 revisions

Welcome to the ColdBox Validation Module

ColdBox sports its own server side validation engine so it can provide you with a unified approach to object and form validation. We have based it on several interfaces, so you can also use any validation framework in your as long as they implement the required interfaces (See the included API Docs).

System Requirements

  • Lucee 4.5+
  • Railo 4+
  • ColdFusion 9+

Introduction

ColdBox validation is based on a way to declaratively specify validation rules for properties or fields in an object or form. The constraints can exist inside of the target object or you can define object and form constraints in your ColdBox configuration file so you can reuse validation constraints or as we call them: shared constraints.

Instructions

Just drop into your modules folder or use CommandBox to install

box install cbvalidation

The module will register several objects into WireBox using the @cbvalidation namespace. The validation manager is registered as ValidationManager@cbvalidation

Mixins

The module will also register two methods in your handlers/interceptors/layouts/views

/**
* Validate an object or structure according to the constraints rules.
* @target An object or structure to validate
* @fields The fields to validate on the target. By default, it validates on all fields
* @constraints A structure of constraint rules or the name of the shared constraint rules to use for validation
* @locale The i18n locale to use for validation messages
* @excludeFields The fields to exclude in the validation
* 
* @return cbvalidation.model.result.IValidationResult
*/
function validateModel()

/**
* Retrieve the application's configured Validation Manager
*/
function getValidationManager()

Settings

Here are the module settings you can place in your ColdBox.cfc by using the validation settings structure:

validation = {
    // The third-party validation manager to use, by default it uses CBValidation.
    manager = "class path",
    // You can store global constraint rules here with unique names
    sharedConstraints = {
        name = {
            field = { constraints here }
        }
    }

}