Welcome Guest, Not a member yet? Register   Sign In
form validation and error count
#1

[eluser]theprodigy[/eluser]
What's the easiest way to get the number of errors while using form_validation?

I would like to display how many errors the user has, in addition to listing them ("You have the following X errors:").

Thanks
#2

[eluser]David Johansson[/eluser]
I think the best way is to extend the Form validation library.
download the attached file and unzip it in the application/libraries folder, then you should be able to call the function:
Code:
$this->form_validation->error_count();
(I haven't tried this, but i guess it would be something similar at least)

or just copy paste the following to a php file called MY_Form_validation.php to the same location.
Code:
<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class MY_Form_validation extends CI_Form_validation {

    function MY_Form_validation()
    {
        parent::CI_Form_validation();
    }

    /**
     * Error Count
     *
     * Returns the the number of errors
     *
     * @access    public
     * @return    int
     */    
    function error_count()
    {
        return count($_error_array);
    }
}
// END Form Validation Class Extention

/* End of file MY_Form_validation.php */
/* Location: ./system/application/libraries/MY_Form_validation.php */
#3

[eluser]David Johansson[/eluser]
actually i think it must be:
Code:
return count($this->_error_array);




Theme © iAndrew 2016 - Forum software by © MyBB