Insert Validation
- Single Page
Posted 12 April 2012 - 06:40 AM
1. accesion_no_first
2. accesion_no_last
The "accesion_no_first" is always less than "accesion_no_last" when I inserting data.
How I create validation?
Please help.
Posted 14 April 2012 - 10:23 AM
Posted 15 April 2012 - 07:06 AM
I use set_rules with a custom callback, but not work.
My code is below:
function book_set()
{
...............................
...............................
$this->grocery_crud->set_rules('acc_first', 'Acc first','trim|required|numeric|callback_bookacc_first_check');
.......................................................
$output = $this->grocery_crud->render();
$this->setup_output($output);
}
public function bookacc_first_check($str)
{
$id = $this->uri->segment(4);
if(!empty($id) && is_numeric($id))
{
$acc_first_old = $this->db->where("id",$id)->get('lib_book')->row()->acc_first;
$this->db->where("acc_no !=",$acc_first_old);
}
$num_row = $this->db->where('acc_no',$str)->get('lib_book')->num_rows();
if ($num_row >= 1)
{
$this->form_validation->set_message('bookacc_first_check', 'The Accession First Number already exists in Book');
return FALSE;
}
else
{
$num_row1 = $this->db->where('acc_no',$str)->get('lib_journal')->num_rows();
if ($num_row1 >= 1)
{
$this->form_validation->set_message('bookacc_first_check', 'The Accession First Number already exists in Journal');
return FALSE;
}
else
{
// here the accepted validation start
$acc_last = $post_array['acc_last'];
if ($str > $acc_last)
{
$this->form_validation->set_message('bookacc_first_check', 'The Acc no. first always less than the Acc no. last');
return FALSE;
}
else
{
return TRUE;
}
}
}
}
If i input the acc_first which is greater than acc_last or vice versa , the validation message is same.
Posted 15 April 2012 - 11:04 AM
$acc_last = $post_array['acc_last'];
to
$acc_last = $_POST['acc_last'];
and
$this->form_validation->set_message('bookacc_first_check', '...');
to
$this->form_validation->set_message('acc_first', '...');
Posted 15 April 2012 - 11:37 AM
I get the desire output only change the
$acc_last = $post_array['acc_last']; to
$acc_last = $_POST['acc_last'];
Thanx again.