Validation

Static object to allow static usage of validation through singleton.

package Fuel
subpackage Core
category Core

 Methods

Special empty method because 0 and '0' are non-empty values

_empty(mixed $val) : bool

Parameters

$val

mixed

Returns

bool

Exact string length

_validation_exact_length(string $val, int $length) : bool

Parameters

$val

string

$length

int

Returns

bool

Match against an array of values

_validation_match_collection(string $val, array $collection, bool $strict) : bool

Parameters

$val

string

$collection

array

$strict

bool

whether to do type comparison

Returns

bool

Match specific other submitted field string value (must be both strings, check is type sensitive)

_validation_match_field(string $val, string $field) : bool

Parameters

$val

string

$field

string

Exceptions

\Validation_Error

Returns

bool

Match PRCE pattern

_validation_match_pattern(string $val, string $pattern) : bool

Parameters

$val

string

$pattern

string

a PRCE regex pattern

Returns

bool

Match value against comparison input

_validation_match_value(mixed $val, mixed $compare, bool $strict) : bool

Parameters

$val

mixed

$compare

mixed

$strict

bool

whether to do type comparison

Returns

bool

Maximum string length

_validation_max_length(string $val, int $length) : bool

Parameters

$val

string

$length

int

Returns

bool

Minimum string length

_validation_min_length(string $val, int $length) : bool

Parameters

$val

string

$length

int

Returns

bool

Checks whether numeric input is between a minimum and a maximum value

_validation_numeric_between(string | float | int $val, float | int $min_val, float | int $max_val) : bool

Parameters

$val

stringfloatint

$min_val

floatint

$max_val

floatint

Returns

bool

Checks whether numeric input has a maximum value

_validation_numeric_max(string | float | int $val, float | int $max_val) : bool

Parameters

$val

stringfloatint

$max_val

floatint

Returns

bool

Checks whether numeric input has a minimum value

_validation_numeric_min(string | float | int $val, float | int $min_val) : bool

Parameters

$val

stringfloatint

$min_val

floatint

Returns

bool

Required

_validation_required(mixed $val) : bool

Value may not be empty

Parameters

$val

mixed

Returns

bool

Conditionally requires completion of current field based on completion of another field

_validation_required_with(mixed $val, string $field) : bool

Parameters

$val

mixed

$field

string

Exceptions

\Validation_Error

Returns

bool

Checks whether string input is valid date format.

_validation_valid_date(string $val, string $format, bool $strict) : bool

When a format is passed it will make sure the date will be in that specific format if validated

Parameters

$val

string

$format

string

The format used at the time of a validation

$strict

bool

Whether validation checks strict

Returns

bool

Validate email using PHP's filter_var()

_validation_valid_email(string $val) : bool

Parameters

$val

string

Returns

bool

Validate email using PHP's filter_var()

_validation_valid_emails(string $val, string $separator) : bool

Parameters

$val

string

$separator

string

Returns

bool

Validate IP using PHP's filter_var()

_validation_valid_ip(string $val, string $flag) : bool

Parameters

$val

string

$flag

string

ipv4|ipv6

Returns

bool

Validate input string with many options

_validation_valid_string(string $val, string | array $flags) : bool

Parameters

$val

string

$flags

stringarray

either a named filter or combination of flags

Returns

bool

Validate URL using PHP's filter_var()

_validation_valid_url(string $val) : bool

Parameters

$val

string

Returns

bool

Fetch the currently active validation instance

active() : \Fuel\Core\Validation

Fetch the field currently being validated

active_field() 

Alias for $this->fieldset->add()

add(string $name, string $label, array $attributes, array $rules) : \Fuel\Core\Fieldset_Field

Parameters

$name

string

$label

string

$attributes

array

$rules

array

Returns

Add Callable

add_callable(string | Object $class) : \Fuel\Core\Validation

Adds an object for which you don't need to write a full callback, just the method as a string will do. This also allows for overwriting functionality from this object because the new class is prepended.

Parameters

$class

stringObject

Classname or object

Returns

\Fuel\Core\Validationthis, to allow chaining

Simpler alias for Validation->add()

add_field(string $name, string $label, string $rules) : \Fuel\Core\Fieldset_Field

depricated Remove in v2.0, passing rules as string is to be removed use add() instead

Parameters

$name

string

Field name

$label

string

Field label

$rules

string

Rules as a piped string

Returns

\Fuel\Core\Fieldset_Field$this to allow chaining

Alias for $this->fieldset->add_model()

add_model(string | Object $class, array | Object $instance, string $method) : \Fuel\Core\Validation

Parameters

$class

stringObject

$instance

arrayObject

$method

string

Returns

Fetch the objects for which you don't need to add a full callback but just the method name

callables() : array

Returns

array

Error

error(string $field, mixed $default) : \Fuel\Core\Validation_Error | array

Return specific error or all errors thrown during validation

Parameters

$field

string

fieldname

$default

mixed

value to return when not validated

Returns

\Fuel\Core\Validation_Errorarraythe validation error object or full array of error objects

Return error message

error_message(string $field, mixed $default) : string | array

Return specific error message or all error messages thrown during validation

Parameters

$field

string

fieldname

$default

mixed

value to return when not validated

Returns

stringarraythe error message or full array of error messages

Alias for $this->fieldset->field()

field(string | null $name, bool $flatten) : \Fuel\Core\Fieldset_Field | false

Parameters

$name

stringnull

$flatten

bool

Returns

Returns the related fieldset

fieldset() : \Fuel\Core\Fieldset

Gets a new instance of the Validation class.

forge(string $fieldset) : \Fuel\Core\Validation

Parameters

$fieldset

string

The name or instance of the Fieldset to link to

Returns

Fetches a specific error message for this validation instance

get_message($rule) : string

Parameters

$rule

string

Returns

string

Fetches the input value from either post or given input

input(string $key, mixed $default) : mixed | array

Parameters

$key

string

$default

mixed

Returns

mixedarraythe input value or full input values array

instance()

instance($name) 

Parameters

$name

remove_callable()

remove_callable($class) 

Parameters

$class

Run validation

run(array $input, bool $allow_partial, $temp_callables) : bool

Performs validation with current fieldset and on given input, will try POST when input wasn't given.

Parameters

$input

array

input that overwrites POST values

$allow_partial

bool

will skip validation of values it can't find or are null

$temp_callables

Returns

bool$temp_callables whether validation succeeded

This will overwrite lang file messages for this validation instance

set_message($rule, $message) : \Fuel\Core\Validation

Parameters

$rule

string

$message

string

Returns

\Fuel\Core\Validationthis, to allow chaining

Show errors

show_errors(array $options) : string

Returns all errors in a list or with set markup from $options param

Parameters

$options

array

uses keys open_list, close_list, open_error, close_error /p>

Returns

string

Validated

validated(string $field, mixed $default) : mixed | array

Returns specific validated value or all validated field=>value pairs

Parameters

$field

string

fieldname

$default

mixed

value to return when not validated

Returns

mixedarraythe validated value or full validated values array

__construct()

__construct($fieldset) 

Parameters

$fieldset

Takes the rule input and formats it into a name & callback

_find_rule(string | array $callback) : array | bool

Parameters

$callback

stringarray

short rule to be called on Validation callables array or full callback

Returns

arrayboolrule array or false when it fails to find something callable

Run rule

_run_rule(callback $rule, mixed $value, array $params, array $field) 

Performs a single rule on a field and its value

Parameters

$rule

callback

$value

mixed

Value by reference, will be edited

$params

array

Extra parameters

$field

array

Validation field description

Exceptions

\Validation_Error

Add error

add_error(string $name, \Fuel\Core\Validation_Error $error) : \Fuel\Core\Validation

Adds an error for a given field.

Parameters

$name

string

field name for which to set the error

$error

\Fuel\Core\Validation_Error

error for the field

Returns

\Fuel\Core\Validationthis, to allow chaining

Set or unset the currently active validation instance

set_active($instance) 

Parameters

$instance

Set or unset the current field being validated

set_active_field($instance) 

Parameters

$instance

 Properties

 

<p>keeps a reference to an instance of Validation while it is being run</p>

$active : \Fuel\Core\Validation

 

<p>keeps a reference to an instance of the Fieldset_Field validation is being run on</p>

$active_field : \Fuel\Core\Fieldset_Field

 

<p>contains a list of classnames and objects that may contain validation methods</p>

$callables : array

 

<p>contains validation error messages, will overwrite those from lang files</p>

$error_messages : array

 

<p>contains Validation_Error instances of encountered errors</p>

$errors : array

 

<p>the fieldset this instance validates</p>

$fieldset : \Fuel\Core\Fieldset

 

<p>whether to fall back to Input::param</p>

$global_input_fallback : bool

 

<p>available after validation started running: contains given input values</p>

$input : array

 

<p>contains values of fields that validated successfully</p>

$validated : array