I'm trying to validate a duplicate entry on my database, the example with duplicate username It works, but when I want use this for a field with a database relations, It doesn't show the message of error like duplicate username's validation example.
In this fuzzy example I want to know if exist a duplicate officeCode:
function employees_management()
{
$crud = new grocery_CRUD();
$crud->set_theme('datatables');
$crud->set_table('employees');
$crud->set_relation('officeCode','offices','city');
$crud->display_as('officeCode','Office City');
// I've tried with callback_before_insert and with rules.
// $crud->callback_before_insert(array($this,'officeCode_check'));
// $crud->set_rules('officeCode', 'Office City','officeCode_check');
$crud->set_subject('Employee');
$crud->required_fields('lastName');
$crud->set_field_upload('file_url','assets/uploads/files');
$output = $crud->render();
$this->_example_output($output);
}
function officeCode_check($str)
{
$num_row = //My query here;
if ($num_row >= 1)
{
$this->set_message('officeCode_check', 'Already updated with this Code!');
return FALSE;
}
else
{
return TRUE;
}
}
I'm something missing?
Regards.