⚠ In case you've missed it, we have migrated to our new website, with a brand new forum. For more details about the migration you can read our blog post for website migration. This is an archived forum. ⚠

  •     

profile picture

Display custom error message



cksuperlatif

cksuperlatif
  • profile picture
  • Member

Posted 04 December 2018 - 16:45 PM

Hello everybody,

 

Sorry for my English I'm french.

 

I want to display custom error message after checking data from another table.

Ex: 1). I have table 'application_profil' that contains each application and profile in it

      2). I want to check if the application and the profile that user submit exist in the table 'application_profil'

           if yes; insert into 'recensement_profil'  if no; display custom error message(this profile doesn't exist in this application)

 

My model:

<?php
class appli_model extends CI_Model  {
	public function __construct()
   {
       parent::__construct();
      
   }
   
   public function checkappli_model($libelle_profil,$libelle_application)
   {
       $this->db->select('Libelle_Profil, Libelle_Application');
       $this->db->from('application_profil');
       $this->db->where('Libelle_Profil',$libelle_profil);
       $this->db->where('Libelle_Application',$libelle_application);
       $this->db->limit(1);
       $query = $this->db->get();
       $result= $query->result();
       $count = count($result);

       return $count;

	}

	}

My controller:

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class applis extends CI_Controller {

    public function __construct()
    {
        parent::__construct();
        $this->load->database();
        $this->load->helper('security');
        $this->load->helper('url');
        $this->load->library('session');
        $this->load->library('grocery_CRUD');

    }
    
    public function index()
    {
         try{
            $crud = new grocery_CRUD();
            $crud->set_theme('flexigrid');
            $crud->set_language('french');
            $crud->set_table('recensement_profil');
            $crud->callback_before_insert(array($this,'_checkapplication',$crud ));


            $output = $crud->render();
            $this->_example_output($output);

        }catch(Exception $e){
            show_error($e->getMessage().' --- '.$e->getTraceAsString());
        }


    }


    function _checkapplication($post_array,$primary_key)
    {
        $this->load->model('appli_model');
        $lipro =	$post_array['Libelle_Profil']	;
        $fkappli = 	$post_array['Libelle_Application'];
        $resultat = 	$this->appli_model->checkappli_model($lipro,$fkappli);


        if ($resultat==1)
        {
                return true;
        }else
            {
                $this->form_validation->set_message('Cet profil nexiste pas sur cette apllication');
                return False;
            }

    }

    public function _example_output($output = null)
    {
        $userdataSession = $this->session->userdata('utilisateur');
        $data_header['usersession']=$userdataSession;

        $this->load->view('include/header');
        $this->load->view('include/top',$data_header);

        $this->load->view('include/menu');
        $this->load->view('applis/applis',$output);

        $this->load->view('include/footer_grocery',$output);

    }

}

xuchunhua

xuchunhua
  • profile picture
  • Member

Posted 15 May 2019 - 02:46 AM

function test_callback($postArray, $primaryKey){
      print_r(json_encode(['success'=>false, 'error_message'=>'your message']));
      die;
}
 
修改 assets/grocery_crud/themes/flexigrid/js/flexigrid-edit.js
 
第70行 form_error_message(message_update_error);改成
 
if(data.hasOwnProperty("error_message")){
          form_error_message(data.error_message);
}else{  
          form_error_message(message_update_error);