Jump to content


Cancel add / insert in some condition

add insert cancel abort

  • Please log in to reply
1 reply to this topic

#1 kifni41

kifni41

    Newbie

  • Members
  • Pip
  • 3 posts

Posted 24 August 2014 - 03: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



#2 Amit Shah

Amit Shah

    grocery CRUD Master

  • Advanced Member
  • PipPipPip
  • 1,192 posts
  • LocationMumbai, India

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

http://www.grocerycr...-before-insert/







Also tagged with one or more of these keywords: add, insert, cancel, abort

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users