Search code examples
phpcodeignitertwitter-bootstrapgrocery-crud

GroceryCrud validation custom messages


I have one question.. How to validate fields data with custom error messages? I use codeigniter, and grocery crud with twitter bootstrap theme, and do some field required, for example:

$crud->set_rules('first_name', 'NAME', 'required'); OR $crud->required_fields('first_name');

Validation work fine, but if validation unsuccessfull - we see just alert with standart message - "An error has occurred on insert\update". How to display custom message that field are required or etc. ? Thanks.


Solution

  • Although this is old topic, but i thing someone can get this error as me just get it.

    We can't use CI set_message function for CroceryCrud validation. Because CroceryCrud use its validation object.

    You can edit libraries/Grocery_CRUD.php, find line "protected function form_validation()",

    at under this function, you can copy it, rename and edit access modifiler to public :

    public function get_form_validation(){
            if($this->form_validation === null)
        {
            $this->form_validation = new grocery_CRUD_Form_validation();
            $ci = &get_instance();
            $ci->load->library('form_validation');
            $ci->form_validation = $this->form_validation;
        }
         return $this->form_validation;
    }
    

    Now, you can call it in your controller :

     $crud-> get_form_validation()->set_message('check_city',"invail %s");