⚠ 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

Insert Validation



tofayelahmed
  • profile picture
  • Member

Posted 12 April 2012 - 06:40 AM

I have two input fieds.

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.

web-johnny
  • profile picture
  • Administrator
  • 1,166 posts

Posted 14 April 2012 - 10:23 AM

You can use the set_rules with a custom callback for that. You can see an example at: /topic/71-different-form-validation-rules-for-insert-and-update/page__view__findpost__p__262

tofayelahmed
  • profile picture
  • Member

Posted 15 April 2012 - 07:06 AM

Thanx for your reply.
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.

web-johnny
  • profile picture
  • Administrator
  • 1,166 posts

Posted 15 April 2012 - 11:04 AM

I think you have to change the:


$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', '...');


tofayelahmed
  • profile picture
  • Member

Posted 15 April 2012 - 11:37 AM

Thanx Johnny.
I get the desire output only change the
$acc_last = $post_array['acc_last']; to
$acc_last = $_POST['acc_last'];
Thanx again.