Hi all...
I need to create somethink like validation when inserting data.
So, before inserting data to db, i check the data with a model function, if pass then continue insert, if not then cancel or abort insert, i need a custom message and redirect to another page if it's cancelled.
So here what come from my brain so far...
1. Using redirect in callback_before insert
function _callback_before_insert($post_array, $primary_key) { $some_id = $post_array['some']; $check = $this->some_model->check($some_id); if($check)){ $this->session->set_flashdata('message','Cannot insert !'); redirect('somewhere/something/'.$post_array['somedata'); }else{ $this->session->set_flashdata('cur_person_id',$person_id); return $post_array; } }
but it's not working, in my experience i cant use redirect in callback ( i tried many time with other cases)
2. Return "false" in _callback_before_insert
function _callback_before_insert($post_array, $primary_key) { $some_id = $post_array['some']; $check = $this->some_model->check($some_id); if($check)){ return false; }else{ $this->session->set_flashdata('cur_person_id',$person_id); return $post_array; } }
It's kind of working, it show alert message and some times popup message ( i dont know why different) said "An error occurred on insert".
But this is now exacly what i need, I need also to custom the message show, and redirect it to another page.
Any suggestion?
PS : sorry for my bad english