⚠ 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

Cancel add / insert in some condition



kifni41
  • profile picture
  • Member

Posted 24 August 2014 - 15:30 PM

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


Amit Shah
  • profile picture
  • Member

Posted 04 September 2014 - 04:37 AM

well my friend - look up the forum for solution - many answers to your queries might already be there

/topic/101-how-to-output-error-message-when-using-callback-before-insert/