Properties

$validation_data

$validation_data : array

Custom data to validate

Type

array

$CI

$CI : object

Reference to the CodeIgniter instance

Type

object

$_field_data

$_field_data : array

Validation data for the current form submission

Type

array

$_config_rules

$_config_rules : array

Validation rules for the current form

Type

array

$_error_array

$_error_array : array

Array of validation errors

Type

array

$_error_messages

$_error_messages : array

Array of custom error messages

Type

array

$_error_prefix

$_error_prefix : string

Start tag for error wrapping

Type

string

$_error_suffix

$_error_suffix : string

End tag for error wrapping

Type

string

$error_string

$error_string : string

Custom error message

Type

string

$_safe_form_data

$_safe_form_data : boolean

Whether the form data has been validated as safe

Type

boolean

Methods

__construct()

__construct(array  $rules = array()) : void

Initialize Form_Validation class

Parameters

array $rules

set_rules()

set_rules(mixed  $field, string  $label = '', mixed  $rules = array(), array  $errors = array()) : \CI_Form_validation

Set Rules

This function takes an array of field names and validation rules as input, any custom error messages, validates the info, and stores it

Parameters

mixed $field
string $label
mixed $rules
array $errors

Returns

\CI_Form_validation

set_data()

set_data(array  $data) : \CI_Form_validation

By default, form validation uses the $_POST array to validate

If an array is set through this method, then this array will be used instead of the $_POST array

Note that if you are validating multiple arrays, then the reset_validation() function should be called after validating each array due to the limitations of CI's singleton

Parameters

array $data

Returns

\CI_Form_validation

set_message()

set_message(  $lang,   $val = '') : \CI_Form_validation

Set Error Message

Lets users set their own error messages on the fly. Note: The key name has to match the function name that it corresponds to.

Parameters

$lang
$val

Returns

\CI_Form_validation

set_error_delimiters()

set_error_delimiters(  $prefix = '<p>',   $suffix = '</p>') : \CI_Form_validation

Set The Error Delimiter

Permits a prefix/suffix to be added to each error message

Parameters

$prefix
$suffix

Returns

\CI_Form_validation

error()

error(string  $field, string  $prefix = '', string  $suffix = '') : string

Get Error Message

Gets the error message associated with a particular field

Parameters

string $field

Field name

string $prefix

HTML start tag

string $suffix

HTML end tag

Returns

string

error_array()

error_array() : array

Get Array of Error Messages

Returns the error messages as an array

Returns

array

error_string()

error_string(  $prefix = '',   $suffix = '') : string

Error String

Returns the error messages as a string, wrapped in the error delimiters

Parameters

$prefix
$suffix

Returns

string

run()

run(string  $group = '') : boolean

Run the Validator

This function does all the work.

Parameters

string $group

Returns

boolean

has_rule()

has_rule(  $field) : boolean

Checks if the rule is present within the validator

Permits you to check if a rule is present within the validator

Parameters

$field

Returns

boolean

set_value()

set_value(  $field = '',   $default = '') : string

Get the value from a form

Permits you to repopulate a form field with the value it was submitted with, or, if that value doesn't exist, with the default

Parameters

$field
$default

Returns

string

set_select()

set_select(  $field = '',   $value = '',   $default = FALSE) : string

Set Select

Enables pull-down lists to be set to the value the user selected in the event of an error

Parameters

$field
$value
$default

Returns

string

set_radio()

set_radio(  $field = '',   $value = '',   $default = FALSE) : string

Set Radio

Enables radio buttons to be set to the value the user selected in the event of an error

Parameters

$field
$value
$default

Returns

string

set_checkbox()

set_checkbox(  $field = '',   $value = '',   $default = FALSE) : string

Set Checkbox

Enables checkboxes to be set to the value the user selected in the event of an error

Parameters

$field
$value
$default

Returns

string

required()

required(  $str) : boolean

Required

Parameters

$str

Returns

boolean

regex_match()

regex_match(  $str,   $regex) : boolean

Performs a Regular Expression match test.

Parameters

$str
$regex

Returns

boolean

matches()

matches(string  $str, string  $field) : boolean

Match one field to another

Parameters

string $str

string to compare against

string $field

Returns

boolean

differs()

differs(  $str,   $field) : boolean

Differs from another field

Parameters

$str
$field

Returns

boolean

is_unique()

is_unique(string  $str, string  $field) : boolean

Is Unique

Check if the input value doesn't already exist in the specified database field.

Parameters

string $str
string $field

Returns

boolean

min_length()

min_length(  $str,   $val) : boolean

Minimum Length

Parameters

$str
$val

Returns

boolean

max_length()

max_length(  $str,   $val) : boolean

Max Length

Parameters

$str
$val

Returns

boolean

exact_length()

exact_length(  $str,   $val) : boolean

Exact Length

Parameters

$str
$val

Returns

boolean

valid_url()

valid_url(string  $str) : boolean

Valid URL

Parameters

string $str

Returns

boolean

valid_email()

valid_email(  $str) : boolean

Valid Email

Parameters

$str

Returns

boolean

valid_emails()

valid_emails(  $str) : boolean

Valid Emails

Parameters

$str

Returns

boolean

valid_ip()

valid_ip(  $ip,   $which = '') : boolean

Validate IP Address

Parameters

$ip
$which

Returns

boolean

alpha()

alpha(  $str) : boolean

Alpha

Parameters

$str

Returns

boolean

alpha_numeric()

alpha_numeric(  $str) : boolean

Alpha-numeric

Parameters

$str

Returns

boolean

alpha_numeric_spaces()

alpha_numeric_spaces(  $str) : boolean

Alpha-numeric w/ spaces

Parameters

$str

Returns

boolean

alpha_dash()

alpha_dash(  $str) : boolean

Alpha-numeric with underscores and dashes

Parameters

$str

Returns

boolean

numeric()

numeric(  $str) : boolean

Numeric

Parameters

$str

Returns

boolean

integer()

integer(  $str) : boolean

Integer

Parameters

$str

Returns

boolean

decimal()

decimal(  $str) : boolean

Decimal number

Parameters

$str

Returns

boolean

greater_than()

greater_than(  $str,   $min) : boolean

Greater than

Parameters

$str
$min

Returns

boolean

greater_than_equal_to()

greater_than_equal_to(  $str,   $min) : boolean

Equal to or Greater than

Parameters

$str
$min

Returns

boolean

less_than()

less_than(  $str,   $max) : boolean

Less than

Parameters

$str
$max

Returns

boolean

less_than_equal_to()

less_than_equal_to(  $str,   $max) : boolean

Equal to or Less than

Parameters

$str
$max

Returns

boolean

in_list()

in_list(  $value,   $list) : boolean

Value should be within an array of values

Parameters

$value
$list

Returns

boolean

is_natural()

is_natural(  $str) : boolean

Is a Natural number (0,1,2,3, etc.)

Parameters

$str

Returns

boolean

is_natural_no_zero()

is_natural_no_zero(  $str) : boolean

Is a Natural number, but not a zero (1,2,3, etc.)

Parameters

$str

Returns

boolean

valid_base64()

valid_base64(  $str) : boolean

Valid Base64

Tests a string for characters outside of the Base64 alphabet as defined by RFC 2045 http://www.faqs.org/rfcs/rfc2045

Parameters

$str

Returns

boolean

prep_for_form()

prep_for_form(mixed  $data) : mixed

Prep data for form

This function allows HTML to be safely shown in a form. Special characters are converted.

Parameters

mixed $data

Input data

Returns

mixed

prep_url()

prep_url(  $str = '') : string

Prep URL

Parameters

$str

Returns

string

strip_image_tags()

strip_image_tags(  $str) : string

Strip Image Tags

Parameters

$str

Returns

string

encode_php_tags()

encode_php_tags(  $str) : string

Convert PHP tags to entities

Parameters

$str

Returns

string

reset_validation()

reset_validation() : \CI_Form_validation

Reset validation vars

Prevents subsequent validation routines from being affected by the results of any previous validation routine due to the CI singleton.

Returns

\CI_Form_validation

_reduce_array()

_reduce_array(  $array,   $keys,   $i) : mixed

Traverse a multidimensional $_POST array index until the data is found

Parameters

$array
$keys
$i

Returns

mixed

_reset_post_array()

_reset_post_array() : void

Re-populate the _POST array with our finalized and processed data

_execute()

_execute(  $row,   $rules,   $postdata = NULL,   $cycles) : mixed

Executes the Validation routines

Parameters

$row
$rules
$postdata
$cycles

Returns

mixed

_get_error_message()

_get_error_message(string  $rule, string  $field) : string

Get the error message for the rule

Parameters

string $rule

The rule name

string $field

The field name

Returns

string

_translate_fieldname()

_translate_fieldname(  $fieldname) : string

Translate a field name

Parameters

$fieldname

Returns

string

_build_error_msg()

_build_error_msg(  $line,   $field = '',   $param = '') : string

Build an error message using the field and param.

Parameters

$line
$field
$param

Returns

string