PHP Class CI_Form_validation, TastyIgniter

Exibir arquivo Open project: tastyigniter/tastyigniter Class Usage Examples

Public Properties

Property Type Description
$validation_data array Custom data to validate

Protected Properties

Property Type Description
$CI object Reference to the CodeIgniter instance
$_config_rules array Validation rules for the current form
$_error_array array Array of validation errors
$_error_messages array Array of custom error messages
$_error_prefix string Start tag for error wrapping
$_error_suffix string End tag for error wrapping
$_field_data array Validation data for the current form submission
$_safe_form_data boolean Whether the form data has been validated as safe
$error_string string Custom error message

Public Methods

Method Description
__construct ( array $rules = [] ) : void Initialize Form_Validation class
alpha ( $str ) : boolean Alpha
alpha_dash ( $str ) : boolean Alpha-numeric with underscores and dashes
alpha_numeric ( $str ) : boolean Alpha-numeric
alpha_numeric_spaces ( $str ) : boolean Alpha-numeric w/ spaces
decimal ( $str ) : boolean Decimal number
differs ( $str, $field ) : boolean Differs from another field
encode_php_tags ( $str ) : string Convert PHP tags to entities
error ( string $field, string $prefix = '', string $suffix = '' ) : string Get Error Message
error_array ( ) : array Get Array of Error Messages
error_string ( $prefix = '', $suffix = '' ) : string Error String
exact_length ( $str, $val ) : boolean Exact Length
greater_than ( $str, $min ) : boolean Greater than
greater_than_equal_to ( $str, $min ) : boolean Equal to or Greater than
has_rule ( $field ) : boolean Checks if the rule is present within the validator
in_list ( $value, $list ) : boolean Value should be within an array of values
integer ( $str ) : boolean Integer
is_natural ( $str ) : boolean Is a Natural number (0,1,2,3, etc.)
is_natural_no_zero ( $str ) : boolean Is a Natural number, but not a zero (1,2,3, etc.)
is_unique ( string $str, string $field ) : boolean Is Unique
less_than ( $str, $max ) : boolean Less than
less_than_equal_to ( $str, $max ) : boolean Equal to or Less than
matches ( string $str, string $field ) : boolean Match one field to another
max_length ( $str, $val ) : boolean Max Length
min_length ( $str, $val ) : boolean Minimum Length
numeric ( $str ) : boolean Numeric
prep_for_form ( mixed $data ) : mixed Prep data for form
prep_url ( $str = '' ) : string Prep URL
regex_match ( $str, $regex ) : boolean Performs a Regular Expression match test.
required ( $str ) : boolean Required
reset_validation ( ) : CI_Form_validation Reset validation vars
run ( string $group = '' ) : boolean Run the Validator
set_checkbox ( $field = '', $value = '', $default = FALSE ) : string Set Checkbox
set_data ( array $data ) : CI_Form_validation By default, form validation uses the $_POST array to validate
set_error_delimiters ( $prefix = '<p>', $suffix = '</p>' ) : CI_Form_validation Set The Error Delimiter
set_message ( $lang, $val = '' ) : CI_Form_validation Set Error Message
set_radio ( $field = '', $value = '', $default = FALSE ) : string Set Radio
set_rules ( mixed $field, string $label = '', mixed $rules = [], array $errors = [] ) : CI_Form_validation Set Rules
set_select ( $field = '', $value = '', $default = FALSE ) : string Set Select
set_value ( $field = '', $default = '' ) : string Get the value from a form
strip_image_tags ( $str ) : string Strip Image Tags
valid_base64 ( $str ) : boolean Valid Base64
valid_email ( $str ) : boolean Valid Email
valid_emails ( $str ) : boolean Valid Emails
valid_ip ( $ip, $which = '' ) : boolean Validate IP Address
valid_url ( string $str ) : boolean Valid URL
xss_clean ( $str ) : string XSS Clean

Protected Methods

Method Description
_build_error_msg ( $line, $field = '', $param = '' ) : string Build an error message using the field and param.
_execute ( $row, $rules, $postdata = NULL, $cycles ) : mixed Executes the Validation routines
_get_error_message ( string $rule, string $field ) : string Get the error message for the rule
_reduce_array ( $array, $keys, $i ) : mixed Traverse a multidimensional $_POST array index until the data is found
_reset_post_array ( ) : void Re-populate the _POST array with our finalized and processed data
_translate_fieldname ( $fieldname ) : string Translate a field name

Method Details

__construct() public method

Initialize Form_Validation class
public __construct ( array $rules = [] ) : void
$rules array
return void

_build_error_msg() protected method

Build an error message using the field and param.
protected _build_error_msg ( $line, $field = '', $param = '' ) : string
return string

_execute() protected method

Executes the Validation routines
protected _execute ( $row, $rules, $postdata = NULL, $cycles ) : mixed
return mixed

_get_error_message() protected method

Get the error message for the rule
protected _get_error_message ( string $rule, string $field ) : string
$rule string The rule name
$field string The field name
return string

_reduce_array() protected method

Traverse a multidimensional $_POST array index until the data is found
protected _reduce_array ( $array, $keys, $i ) : mixed
return mixed

_reset_post_array() protected method

Re-populate the _POST array with our finalized and processed data
protected _reset_post_array ( ) : void
return void

_translate_fieldname() protected method

Translate a field name
protected _translate_fieldname ( $fieldname ) : string
return string

alpha() public method

Alpha
public alpha ( $str ) : boolean
return boolean

alpha_dash() public method

Alpha-numeric with underscores and dashes
public alpha_dash ( $str ) : boolean
return boolean

alpha_numeric() public method

Alpha-numeric
public alpha_numeric ( $str ) : boolean
return boolean

alpha_numeric_spaces() public method

Alpha-numeric w/ spaces
public alpha_numeric_spaces ( $str ) : boolean
return boolean

decimal() public method

Decimal number
public decimal ( $str ) : boolean
return boolean

differs() public method

Differs from another field
public differs ( $str, $field ) : boolean
return boolean

encode_php_tags() public method

Convert PHP tags to entities
public encode_php_tags ( $str ) : string
return string

error() public method

Gets the error message associated with a particular field
public error ( string $field, string $prefix = '', string $suffix = '' ) : string
$field string Field name
$prefix string HTML start tag
$suffix string HTML end tag
return string

error_array() public method

Returns the error messages as an array
public error_array ( ) : array
return array

error_string() public method

Returns the error messages as a string, wrapped in the error delimiters
public error_string ( $prefix = '', $suffix = '' ) : string
return string

exact_length() public method

Exact Length
public exact_length ( $str, $val ) : boolean
return boolean

greater_than() public method

Greater than
public greater_than ( $str, $min ) : boolean
return boolean

greater_than_equal_to() public method

Equal to or Greater than
public greater_than_equal_to ( $str, $min ) : boolean
return boolean

has_rule() public method

Permits you to check if a rule is present within the validator
public has_rule ( $field ) : boolean
return boolean

in_list() public method

Value should be within an array of values
public in_list ( $value, $list ) : boolean
return boolean

integer() public method

Integer
public integer ( $str ) : boolean
return boolean

is_natural() public method

Is a Natural number (0,1,2,3, etc.)
public is_natural ( $str ) : boolean
return boolean

is_natural_no_zero() public method

Is a Natural number, but not a zero (1,2,3, etc.)
public is_natural_no_zero ( $str ) : boolean
return boolean

is_unique() public method

Check if the input value doesn't already exist in the specified database field.
public is_unique ( string $str, string $field ) : boolean
$str string
$field string
return boolean

less_than() public method

Less than
public less_than ( $str, $max ) : boolean
return boolean

less_than_equal_to() public method

Equal to or Less than
public less_than_equal_to ( $str, $max ) : boolean
return boolean

matches() public method

Match one field to another
public matches ( string $str, string $field ) : boolean
$str string string to compare against
$field string
return boolean

max_length() public method

Max Length
public max_length ( $str, $val ) : boolean
return boolean

min_length() public method

Minimum Length
public min_length ( $str, $val ) : boolean
return boolean

numeric() public method

Numeric
public numeric ( $str ) : boolean
return boolean

prep_for_form() public method

This function allows HTML to be safely shown in a form. Special characters are converted.
Deprecation: 3.0.6 Not used anywhere within the framework and pretty much useless
public prep_for_form ( mixed $data ) : mixed
$data mixed Input data
return mixed

prep_url() public method

Prep URL
public prep_url ( $str = '' ) : string
return string

regex_match() public method

Performs a Regular Expression match test.
public regex_match ( $str, $regex ) : boolean
return boolean

required() public method

Required
public required ( $str ) : boolean
return boolean

reset_validation() public method

Prevents subsequent validation routines from being affected by the results of any previous validation routine due to the CI singleton.
public reset_validation ( ) : CI_Form_validation
return CI_Form_validation

run() public method

This function does all the work.
public run ( string $group = '' ) : boolean
$group string
return boolean

set_checkbox() public method

Enables checkboxes to be set to the value the user selected in the event of an error
public set_checkbox ( $field = '', $value = '', $default = FALSE ) : string
return string

set_data() public method

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
public set_data ( array $data ) : CI_Form_validation
$data array
return CI_Form_validation

set_error_delimiters() public method

Permits a prefix/suffix to be added to each error message
public set_error_delimiters ( $prefix = '<p>', $suffix = '</p>' ) : CI_Form_validation
return CI_Form_validation

set_message() public method

Lets users set their own error messages on the fly. Note: The key name has to match the function name that it corresponds to.
public set_message ( $lang, $val = '' ) : CI_Form_validation
return CI_Form_validation

set_radio() public method

Enables radio buttons to be set to the value the user selected in the event of an error
public set_radio ( $field = '', $value = '', $default = FALSE ) : string
return string

set_rules() public method

This function takes an array of field names and validation rules as input, any custom error messages, validates the info, and stores it
public set_rules ( mixed $field, string $label = '', mixed $rules = [], array $errors = [] ) : CI_Form_validation
$field mixed
$label string
$rules mixed
$errors array
return CI_Form_validation

set_select() public method

Enables pull-down lists to be set to the value the user selected in the event of an error
public set_select ( $field = '', $value = '', $default = FALSE ) : string
return string

set_value() public method

Permits you to repopulate a form field with the value it was submitted with, or, if that value doesn't exist, with the default
public set_value ( $field = '', $default = '' ) : string
return string

strip_image_tags() public method

Strip Image Tags
public strip_image_tags ( $str ) : string
return string

valid_base64() public method

Tests a string for characters outside of the Base64 alphabet as defined by RFC 2045 http://www.faqs.org/rfcs/rfc2045
public valid_base64 ( $str ) : boolean
return boolean

valid_email() public method

Valid Email
public valid_email ( $str ) : boolean
return boolean

valid_emails() public method

Valid Emails
public valid_emails ( $str ) : boolean
return boolean

valid_ip() public method

Validate IP Address
public valid_ip ( $ip, $which = '' ) : boolean
return boolean

valid_url() public method

Valid URL
public valid_url ( string $str ) : boolean
$str string
return boolean

xss_clean() public method

XSS Clean
public xss_clean ( $str ) : string
return string

Property Details

$CI protected_oe property

Reference to the CodeIgniter instance
protected object $CI
return object

$_config_rules protected_oe property

Validation rules for the current form
protected array $_config_rules
return array

$_error_array protected_oe property

Array of validation errors
protected array $_error_array
return array

$_error_messages protected_oe property

Array of custom error messages
protected array $_error_messages
return array

$_error_prefix protected_oe property

Start tag for error wrapping
protected string $_error_prefix
return string

$_error_suffix protected_oe property

End tag for error wrapping
protected string $_error_suffix
return string

$_field_data protected_oe property

Validation data for the current form submission
protected array $_field_data
return array

$_safe_form_data protected_oe property

Whether the form data has been validated as safe
protected bool $_safe_form_data
return boolean

$error_string protected_oe property

Custom error message
protected string $error_string
return string

$validation_data public_oe property

Custom data to validate
public array $validation_data
return array