-
Notifications
You must be signed in to change notification settings - Fork 0
CI_Form_validation
Form Validation Class
- Class name: CI_Form_validation
- Namespace:
protected object $CI
Reference to the CodeIgniter instance
- Visibility: protected
protected array $_field_data = array()
Validation data for the current form submission
- Visibility: protected
protected array $_config_rules = array()
Validation rules for the current form
- Visibility: protected
protected array $_error_array = array()
Array of validation errors
- Visibility: protected
protected array $_error_messages = array()
Array of custom error messages
- Visibility: protected
protected string $_error_prefix = '<p>'
Start tag for error wrapping
- Visibility: protected
protected string $_error_suffix = '</p>'
End tag for error wrapping
- Visibility: protected
protected string $error_string = ''
Custom error message
- Visibility: protected
protected boolean $_safe_form_data = FALSE
Whether the form data has been validated as safe
- Visibility: protected
public array $validation_data = array()
Custom data to validate
- Visibility: public
void CI_Form_validation::__construct(array $rules)
Initialize Form_Validation class
- Visibility: public
- $rules array
\CI_Form_validation CI_Form_validation::set_rules(mixed $field, string $label, mixed $rules, array $errors)
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
- Visibility: public
- $field mixed
- $label string
- $rules mixed
- $errors array
\CI_Form_validation CI_Form_validation::set_data(array $data)
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
- Visibility: public
- $data array
\CI_Form_validation CI_Form_validation::set_message($lang, $val)
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.
- Visibility: public
- $lang mixed
- $val mixed
\CI_Form_validation CI_Form_validation::set_error_delimiters($prefix, $suffix)
Set The Error Delimiter
Permits a prefix/suffix to be added to each error message
- Visibility: public
- $prefix mixed
- $suffix mixed
string CI_Form_validation::error(string $field, string $prefix, string $suffix)
Get Error Message
Gets the error message associated with a particular field
- Visibility: public
- $field string - <p>Field name</p>
- $prefix string - <p>HTML start tag</p>
- $suffix string - <p>HTML end tag</p>
array CI_Form_validation::error_array()
Get Array of Error Messages
Returns the error messages as an array
- Visibility: public
string CI_Form_validation::error_string($prefix, $suffix)
Error String
Returns the error messages as a string, wrapped in the error delimiters
- Visibility: public
- $prefix mixed
- $suffix mixed
boolean CI_Form_validation::run(string $group)
Run the Validator
This function does all the work.
- Visibility: public
- $group string
mixed CI_Form_validation::_reduce_array($array, $keys, $i)
Traverse a multidimensional $_POST array index until the data is found
- Visibility: protected
- $array mixed
- $keys mixed
- $i mixed
void CI_Form_validation::_reset_post_array()
Re-populate the _POST array with our finalized and processed data
- Visibility: protected
mixed CI_Form_validation::_execute($row, $rules, $postdata, $cycles)
Executes the Validation routines
- Visibility: protected
- $row mixed
- $rules mixed
- $postdata mixed
- $cycles mixed
string CI_Form_validation::_translate_fieldname($fieldname)
Translate a field name
- Visibility: protected
- $fieldname mixed
string CI_Form_validation::_build_error_msg($line, $field, $param)
Build an error message using the field and param.
- Visibility: protected
- $line mixed
- $field mixed
- $param mixed
boolean CI_Form_validation::has_rule($field)
Checks if the rule is present within the validator
Permits you to check if a rule is present within the validator
- Visibility: public
- $field mixed
string CI_Form_validation::set_value($field, $default)
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
- Visibility: public
- $field mixed
- $default mixed
string CI_Form_validation::set_select($field, $value, $default)
Set Select
Enables pull-down lists to be set to the value the user selected in the event of an error
- Visibility: public
- $field mixed
- $value mixed
- $default mixed
string CI_Form_validation::set_radio($field, $value, $default)
Set Radio
Enables radio buttons to be set to the value the user selected in the event of an error
- Visibility: public
- $field mixed
- $value mixed
- $default mixed
string CI_Form_validation::set_checkbox($field, $value, $default)
Set Checkbox
Enables checkboxes to be set to the value the user selected in the event of an error
- Visibility: public
- $field mixed
- $value mixed
- $default mixed
boolean CI_Form_validation::required($str)
Required
- Visibility: public
- $str mixed
boolean CI_Form_validation::regex_match($str, $regex)
Performs a Regular Expression match test.
- Visibility: public
- $str mixed
- $regex mixed
boolean CI_Form_validation::matches(string $str, string $field)
Match one field to another
- Visibility: public
- $str string - <p>string to compare against</p>
- $field string
boolean CI_Form_validation::differs($str, $field)
Differs from another field
- Visibility: public
- $str mixed
- $field mixed
boolean CI_Form_validation::is_unique(string $str, string $field)
Is Unique
Check if the input value doesn't already exist in the specified database field.
- Visibility: public
- $str string
- $field string
boolean CI_Form_validation::min_length($str, $val)
Minimum Length
- Visibility: public
- $str mixed
- $val mixed
boolean CI_Form_validation::max_length($str, $val)
Max Length
- Visibility: public
- $str mixed
- $val mixed
boolean CI_Form_validation::exact_length($str, $val)
Exact Length
- Visibility: public
- $str mixed
- $val mixed
boolean CI_Form_validation::valid_url(string $str)
Valid URL
- Visibility: public
- $str string
boolean CI_Form_validation::valid_email($str)
Valid Email
- Visibility: public
- $str mixed
boolean CI_Form_validation::valid_emails($str)
Valid Emails
- Visibility: public
- $str mixed
boolean CI_Form_validation::valid_ip($ip, $which)
Validate IP Address
- Visibility: public
- $ip mixed
- $which mixed
boolean CI_Form_validation::alpha($str)
Alpha
- Visibility: public
- $str mixed
boolean CI_Form_validation::alpha_numeric($str)
Alpha-numeric
- Visibility: public
- $str mixed
boolean CI_Form_validation::alpha_numeric_spaces($str)
Alpha-numeric w/ spaces
- Visibility: public
- $str mixed
boolean CI_Form_validation::alpha_dash($str)
Alpha-numeric with underscores and dashes
- Visibility: public
- $str mixed
boolean CI_Form_validation::numeric($str)
Numeric
- Visibility: public
- $str mixed
boolean CI_Form_validation::integer($str)
Integer
- Visibility: public
- $str mixed
boolean CI_Form_validation::decimal($str)
Decimal number
- Visibility: public
- $str mixed
boolean CI_Form_validation::greater_than($str, $min)
Greater than
- Visibility: public
- $str mixed
- $min mixed
boolean CI_Form_validation::greater_than_equal_to($str, $min)
Equal to or Greater than
- Visibility: public
- $str mixed
- $min mixed
boolean CI_Form_validation::less_than($str, $max)
Less than
- Visibility: public
- $str mixed
- $max mixed
boolean CI_Form_validation::less_than_equal_to($str, $max)
Equal to or Less than
- Visibility: public
- $str mixed
- $max mixed
boolean CI_Form_validation::in_list($value, $list)
Value should be within an array of values
- Visibility: public
- $value mixed
- $list mixed
boolean CI_Form_validation::is_natural($str)
Is a Natural number (0,1,2,3, etc.)
- Visibility: public
- $str mixed
boolean CI_Form_validation::is_natural_no_zero($str)
Is a Natural number, but not a zero (1,2,3, etc.)
- Visibility: public
- $str mixed
boolean CI_Form_validation::valid_base64($str)
Valid Base64
Tests a string for characters outside of the Base64 alphabet as defined by RFC 2045 http://www.faqs.org/rfcs/rfc2045
- Visibility: public
- $str mixed
string CI_Form_validation::prep_for_form($data)
Prep data for form
This function allows HTML to be safely shown in a form. Special characters are converted.
- Visibility: public
- $data mixed
string CI_Form_validation::prep_url($str)
Prep URL
- Visibility: public
- $str mixed
string CI_Form_validation::strip_image_tags($str)
Strip Image Tags
- Visibility: public
- $str mixed
string CI_Form_validation::encode_php_tags($str)
Convert PHP tags to entities
- Visibility: public
- $str mixed
\CI_Form_validation CI_Form_validation::reset_validation()
Reset validation vars
Prevents subsequent validation routines from being affected by the results of any previous validation routine due to the CI singleton.
- Visibility: public