/** * Validates the values of the record against the database and any additional validation rules * * @throws fValidationException When the record, or one of the associated records, violates one of the validation rules for the class or can not be properly stored in the database * * @param boolean $return_messages If an array of validation messages should be returned instead of an exception being thrown * @param boolean $remove_column_names If column names should be removed from the returned messages, leaving just the message itself * @return void|array If $return_messages is TRUE, an array of validation messages will be returned */ public function validate($return_messages = FALSE, $remove_column_names = FALSE) { $class = get_class($this); if (fORM::getActiveRecordMethod($class, 'validate')) { return $this->__call('validate', array($return_messages)); } $validation_messages = array(); fORM::callHookCallbacks($this, 'pre::validate()', $this->values, $this->old_values, $this->related_records, $this->cache, $validation_messages); // Validate the local values $local_validation_messages = fORMValidation::validate($this, $this->values, $this->old_values); // Validate related records $related_validation_messages = fORMValidation::validateRelated($this, $this->values, $this->related_records); $validation_messages = array_merge($validation_messages, $local_validation_messages, $related_validation_messages); fORM::callHookCallbacks($this, 'post::validate()', $this->values, $this->old_values, $this->related_records, $this->cache, $validation_messages); $validation_messages = fORMValidation::replaceMessages($class, $validation_messages); $validation_messages = fORMValidation::reorderMessages($class, $validation_messages); if ($return_messages) { if ($remove_column_names) { $validation_messages = fValidationException::removeFieldNames($validation_messages); } return $validation_messages; } if (!empty($validation_messages)) { throw new fValidationException('The following problems were found:', $validation_messages); } }