Search code examples
phpoopcodeignitercodeigniter-2

CodeIgniter Validation Errors - how to get an array of key => value pairs?


Assuming a form with errors, is there a way to get an array of key (the field name) / value (the error message) pairs? For example:

['name'] => 'The name field is required',
['age'] => 'The name must be greater than 18'

If there is no native way to do this, I will extend the form validation library and expose the protected property *_error_array*.


Solution

  • I ended up extending the core class:

    class MY_Form_validation extends CI_Form_validation
    {
        public function error_array()
        {
            return $this->_error_array;
        }
    }