CodeIgniter Forums
need some help Grocery CRUD form validation - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forum-21.html)
+--- Thread: need some help Grocery CRUD form validation (/thread-61070.html)



need some help Grocery CRUD form validation - El Forum - 09-11-2014

[eluser]Unknown[/eluser]
hi all,

first, i have started learning PHP and frameworks CodeIgniter & Grocery CRUD, i registered on Grocery CRUD forum but i can't make a new Topic and also can't reply to any topic ?? so i am here to ask this question related to Grocery CRUD.

i want to validate an entry before insertion from a table. ( for some reason, i do not want to use any dropdown and set_relation ). need some code how to achieve it.

1) i have two tables a) employees and b) departments
2) employees table contain a column DeptID which is same as in departments table
3) when user enter DeptID, the method check and get column DeptName on a callback_column, this will not only disply the name of department but also verify the DeptID column value
4) if not present, raise an error like "Error: Invalid Deparment ID... " otherwise allow INSERT / UPDATE

please inform, when we can create Master/Detail like Forms using Grocery CRUD?

kindly help me.
regards.

Sorry, forgot to mention here what i did... please find below

Code:
public function manage_employees()
{
   $crud = new grocery_CRUD();

   $crud->set_theme('datatables');
   $crud->set_table('employees');
   $crud->columns('EmployeeID', 'EmployeeName', 'DeptID', 'DeptName', 'Salary', 'Commission', 'Total');
   $crud->display_as('EmployeeID','Employee Code')
     ->display_as('EmployeeName','Employee Name')
     ->display_as('DeptID','Department ID')
     ->display_as('DeptName','Department Name') /* NOT A DATABASE COLUMN */
     ->display_as('Salary','Salary')
     ->display_as('Commission','Commission')
     ->display_as('Total','Total Salary');  /* NOT A DATABASE COLUMN */
   $crud->set_subject('Employees Management');
   $crud->callback_column('Total',array($this,'totalSalary')); /* To display Total Salary */

   $output = $crud->render();

   $this->mytest_output($output);
  
}
public function totalSalary($value, $row)
{
    return $value.($row->Salary + $row->Commission);
}