There are two ways to validate content inputs in webCOMAND.
- Content Validation - Define content validation rules associated with a content type.
- Web Form Validation - Define web form input validation in web app code.
It is also possible to combine these two methods when appropriate.
Content validation ensures that only valid field values can be approved or saved.
- Custom Model validate() Method - If a content type model overrides the default validate() method, a custom validation process will be executed in PHP code. It is up to that code to define the validation process, which can log errors, throw a validation_exception and/or call parent::validate() to continue the default validation process. If the default validation process is not invoked, validation will only fail if a validation_exception is throw. Logged errors and the return value will not prevent approve or save from completing.
- Default validate() Method - If a content type model does not override the default validate() method, or it is still invoked by parent::validate(), the following validation steps will occur.
- Content Type Validate Template - If a Validate Template is defined for the object's content type or one that it extends, content validation will be performed in the corresponding cTemplate code. If errors are logged and TRUE or FALSE is not returned, validation will fail. If FALSE is returned, validation will fail, regardless of logged errors. If TRUE is returned, validation will pass, regardless of logged errors. If FALSE is returned, subsequent steps below will be skipped.
- Model method__Validate() Method - If a Validate Template is not defined, but a model method__Validate() method is defined, content validation will be performed in that PHP code. Errors can be logged, but validation will only fail if FALSE is returned. If FALSE is returned, subsequent steps below will be skipped.
- Default Field Type Validations - Content type fields of certain data types, such as a Number or Date, will be automatically validated based on their data type.
- Custom Field Validations - Process any field-specific validation rules, including free-form regular expressions.
In addition to the process above, which occurs before an object is approved or saved, the webCOMAND UI (Form View) will process both field validation in the browser, as inputs are modified. The UI will prevent approve or save in the browser until those validations are satisfied first.
In addition to the repository object and content validation listed above, general-purpose web form validation is also supported through the following classes in the PHP API io_comand_web package.
- validate - Prepare and validate HTML form submission values.
- request - The request::update() method indirectly apply object and content validations when the write option is set to 'approve' or 'save'.
- form - The form::update() method indirectly apply object and content validations when the write option is set to 'approve' or 'save'.