I have tried to test validation with rule to see if record are in the database before create a new record. This works as expected.
But I can't update a row when the rule are enabled in the code. Any idea why it stop with the loading message (see picture)
[sharedmedia=core:attachments:320]
Here are my code:
public function employees()
{
$crud = new grocery_CRUD();
$crud->set_subject('Employee');
$crud->set_table('employees');
$crud->set_theme('datatables');
//$crud->unset_delete();
//$crud->unset_columns('file_url');
//$crud->set_language('danish');
//$crud->set_lang_string('form_save','Save customer into the database');
$crud->set_rules('email', 'Email','trim|required|xss_clean|callback_email_check');
//$crud->add_action('More', '', 'demo/action_more','ui-icon-plus');
$output = $crud->render();
$this->_example_output($output);
}
public function email_check($str)
{
$id = $this->uri->segment(4);
if(!empty($id) && is_numeric($id))
{
$email_old = $this->db->where("id",$id)->get('employees')->row()->email;
$this->db->where("email !=",$username_old);
}
$num_row = $this->db->where('email',$str)->get('employees')->num_rows();
if ($num_row >= 1)
{
$this->form_validation->set_message('email_check', 'The email already exists');
return FALSE;
}
else
{
return TRUE;
}
}
function _example_output($output = null)
{
$this->load->view('our_template.php',$output);
}
Best Regards
Jesper Vels