date
title
deposit
withdraw
I want to show the add/edit form the following fields:
date
title
amount
type (deposit or withdraw)
I want the user to select whether the type of this transaction he's adding is of deposit or withdraw, and then before insertion I want the system to figure out what user has selected, and then set the field value (either deposit or withdraw) to what he has chosen, from the field of amount.
But the problem is, I can't add a custom field to the add/edit form that doesn't exist in database, because if I do, the insertion of CRUD simply fails.
Here's some code snippet, can anyone help?
// Set title or subject of this CRUD
$crud->set_subject('Transaction');
// Set database table name for CRUD operations
$crud->set_table('transactions');
// Set Relation of tables for CRUD operations
$crud->set_relation('category_id','category', 'title');
// Columns for Grid
$crud->columns('date','title','category_id', 'deposit', 'withdraw', 'balance');
$crud->unset_fields('deposit','withdraw');
// Order by
$crud->order_by('date','asc');
// Load custom Transactions_model
$crud->set_model('Transactions_model');
// Callbacks for columns on grid
//$crud->callback_column('deposit',array($this,'transaction_type'));
//$crud->callback_column('balance',array($this,'transaction_balance'));
// Display field as
$crud->display_as('title','Description');
$crud->display_as('category_id','Category');
// Fields for add/edit form
//$crud->fields('date','title','deposit','withdraw','amount','category_id');
// Hide some fields from add/edit form from user
// $crud->change_field_type('deposit','invisible');
// $crud->change_field_type('withdraw','invisible');
// Required fields
$crud->required_fields('date','title','category_id');
// Callback on field on add/edit form
//$crud->callback_before_insert(array($this,'amount_callback'));
// Render Crud
$output = $crud->render();
// Load view
$this->_transactions_output($output);