Validator Class
This class is used in MY_Model and the Form class. Does not require post data and is a little more generic then the CI Validation class. The validator_helper that contains many helpful rule functions is automatically loaded.
Properties Reference
Property | Default Value | Description |
---|---|---|
public | ||
field_error_delimiter | \n | Delimiter for rendering multiple errors for a field |
stack_field_errors | none | Stack multiple field errors if any or just replace with the newest |
register_to_global_errors | 1 | Will add to the globals error array |
load_helpers | 1 | Will automatically load the validator helpers |
protected | ||
_fields | N/A | Fields to validate |
_errors | N/A | Errors after running validation |
Function Reference [+]
$this->validator->initialize([$params=array()])
Initialize preferences.
Returns
void
Parameters
(array) $params
$this->validator->set_params($params)
Set object parameters.
Returns
void
Parameters
(array) $params
$this->validator->add_rule('$field', '$func', '$msg', [$params=array()])
Add processing rule (function) to an input variable. The validator_helper contains many helpful rule functions you can use.
Returns
void
Parameters
(string) $field key in processing array to assign to rule. Often times its the same name as the field input (string) $func error message (string) $msg function for processing (mixed) $params function arguments with the first usually being the posted value. If multiple arguments need to be passed, then you can use an array.
$this->validator->remove_rule('$field', ['$func'=NULL])
Removes rule from validation.
Returns
void
Parameters
(string) $field field to remove (string) $func key for rule (can have more then one rule for a field) (optional)
$this->validator->validate([$values=array()], ['$stop_on_first'=FALSE], ['$reset'=TRUE])
Runs through validation.
Returns
boolean
Parameters
(array) $values assoc array of values to validate (optional) (boolean) $stop_on_first exit on first error? (optional) (boolean) $reset reset validation errors (optional)
$this->validator->is_valid()
Checks to see if it validates.
Returns
boolean
$this->validator->catch_error('$msg', ['$key'=NULL])
Catches error into the global array.
Returns
string key of variable input
Parameters
(string) $msg msg error message (mixed) $key key to identify error message
$this->validator->catch_errors($errors, ['$key'=NULL])
Catches multiple errors.
Returns
string key of variable input
Parameters
(array) $errors of error messages (key) $key of error message if a single message
$this->validator->get_errors()
Retrieve errors.
Returns
assoc array of errors and messages
$this->validator->get_error('$key')
Retrieves a single error.
Returns
string error message
Parameters
(mixed) $key key to error message
$this->validator->get_last_error()
Retrieves the last error message.
Returns
string error message
$this->validator->fields()
Returns the fields with rules.
Returns
array
$this->validator->clear()
Same as reset.
Returns
void
$this->validator->reset(['$remove_fields'=TRUE])
Resets rules and errors.
Returns
void