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*.

有帮助吗?

解决方案

I ended up extending the core class:

class MY_Form_validation extends CI_Form_validation
{
    public function error_array()
    {
        return $this->_error_array;
    }
}
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top