i would like to validate form with validator class

edited October 2012 in Modules
I am using

$this->load->library('validator'); class and

$this->validator->add_rule('first_name', 'required', 'Please enter in an first name', $this->input->post('first_name'));
$this->validator->add_rule('last_name', 'required', 'Please enter in an last name', $this->input->post('last_name'));

if ($this->validator->validate())
{
// valid
} else {
// unvalid
}

if is unvalid i woud like to show errors like "Please enter in an first name" and "Please enter in an last name". How to print this error on the front end view? I am not using form builders...

Thank you

Comments

  • edited 10:47PM
    There are a couple validate functions you can use to help with that in the validator_helper. There is a display_errors() function which will output an unordered list of errors and a get_errors() function you can use which will return an array of errors.
  • edited 10:47PM
    thank you for replay. Can i use this two functions on the view? becouse i get error that functions does not exist on view. I want to show errors on the view not controller.

    Thank you
  • edited 10:47PM
    Sure. Just be sure to load the validator helpers for the view. You can do that in the controller or even the view itself:
    // from view $CI =& get_instance(); $CI->load->helper('validator');
Sign In or Register to comment.