⚠ 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

How to add valdation by callback



tofayelahmed

tofayelahmed
  • profile picture
  • Member

Posted 24 July 2012 - 06:41 AM

Hello everybody.
I want to add some condition during the insert.
The condition uses more than one tables.
If support the condition then insert otherwise show mesage and not insert.
I attach a image.
Here amount field data entry depend on leave name field.

Example: if 'leave name' = 'Annual'

and 'amount' = 20.

I get the data annual leave balance from another table by using ;leave name' and check if 'amount' is greater than 'annual leave balance' then show wrong message.


public function leave_trans()
{
$this->grocery_crud->set_table('nlg_leave_log');
$this->grocery_crud->set_subject('Leave');
$this->grocery_crud->required_fields('emp_id','amount','date_leave','leave_name');
$this->grocery_crud->set_relation('emp_id','nlg_emp_info','emp_id');
$this->grocery_crud->set_relation('leave_name','nlg_leave','leave_name');
$this->grocery_crud->change_field_type('user','invisible');
$this->grocery_crud->callback_before_insert(array($this,'leave_amount_check'));
$this->grocery_crud->callback_before_insert(array($this,'user_calback'));
$this->grocery_crud ->display_as('emp_id','Employee ID')
->display_as('date_leave','Date Leave')
->display_as('leave_name','Leave Name');

$output = $this->grocery_crud->render();
$this->crud_output($output);
}

function leave_amount_check($primary_key)
{
$id = $primary_key;
$amount = $post_array['amount'];
$date_leave = $post_array['date_leave'];
$leave_name = $post_array['leave_name'];
$this->db->select('*');
$this->db->where('id',$leave_name);

$query = $this->db->get('nlg_leave');

foreach ($query->result() as $row)
{
$leave_balance = $row->leave_balance;
}
if($amount > $leave_balance)
{
return false;
}
else
{
return true;
}
}



This code is not working.
Please help.


.