⚠ 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

db-insert with added field



R2D2

R2D2
  • profile picture
  • Member

Posted 30 September 2012 - 07:15 AM

Hi there again,

i have a callback_add_field, which looks like this

$this->grocery_crud->fields(.... , 'Test', ...);
$this->grocery_crud->callback_add_field('Test',array($this,'getTest'));

function getSpiele() {
$out = "<input id='field-Test' type='text' name='Test' />";
return $out;
}


And a callback_after_insert:


$this->grocery_crud->callback_after_insert(array($this, 'getTest'));

function getTest($post_array,$primary_key) {
$test = array(
"id" => $primary_key,
"test" => $post_array['Test']
);

$this->db->insert('test', $test);
}


using this, works fine, but the $post_array['Test'] doesn't work, why, how can it be solved?

$test = array(
"id" => $primary_key,
);



Thanks in advance,
R2D2

midnigther

midnigther
  • profile picture
  • Member

Posted 30 September 2012 - 13:39 PM

If you add a new field to grocery crud you should do the insert query manually otherwise unset the test field.
When you call active recordr from $this->db->insert the CI generates the insert sql query without the test field.