⚠ 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

about the fake filed ?



wa7eedem
  • profile picture
  • Member

Posted 22 May 2012 - 06:42 AM

hi all

I new to GC and I found it very easy to use and to learn

the documentation and the forum help me alot and thanks to any one have a hand in this :)

I have a situation , I want to add data to another table after submit the form so I use :

callback_after_insert


and add a fake filed I called it [color=#ff0000]whem[/color]

like this :






....


$crud = new grocery_CRUD();

$crud->set_table('customers');
$crud->set_subject("customers");

$crud->add_fields('C_full_name','whem','C_email','C_mobile');

$crud->callback_after_insert('whem',array($this,add_whem));

$output = $crud->render();



.....




public function add_whem($post_array,$primary_key)
{
$whem_data = array(
"CF_C_id" => $primary_key,
"CF_name" => $post_array['whem']
);

$this->db->insert('customers_followers',$whem_data);

return true;
}


the filed appears in the form , but after submit nothing happen , and I found the error from firebug in the URL

http://localhost/APP/index.php/admin/customers/index/insert


with this error :



Error Number: 1054

Unknown column 'whem' in 'field list'
INSERT INTO `customers` (`C_full_name`, `whem`, `C_email`, `C_mobile`)

Filename: DB_driver.php
Line Number: 330


its should not use the fake field [color=#ff0000]whem [/color]in the insert ! and I dont know why ?

I hope found the help

thank you ..

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

Posted 22 May 2012 - 06:48 AM

The "invisible" field does exactly this thing.

$crud->fields('C_full_name','C_email',....,'whem');
$crud->change_field_type('whem','invisible');

for security reasons grocery CRUD removes every post field that doesn't recognize

For more you can take a look at: http://www.grocerycrud.com/documentation/options_functions/change_field_type#invisible-field

wa7eedem
  • profile picture
  • Member

Posted 22 May 2012 - 10:11 AM

thanks johnny ,

still no luck ...

I add the "invisible" field still have the error : Unknown column 'whem' in 'field list'

and as I understand from the link above the "invisible" field will not showing the field in the form , but still te field apper ...


but that not what I want ...

I want the user fill the data for all fields and insert some data in the main table and the others in the sub table

I hope you Follow me now ...


thank you ...

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

Posted 22 May 2012 - 22:19 PM

Oooops :blink: I am sorry I understood a wrong thing.

So in your case you need the callback_insert so you will escape all the automatic insert. So in your case you will do something like this:


$crud->callback_insert(array($this,'insert_and_add_whem'));


and your callback will be something like:


function insert_and_add_whem($post_array){

$CF_name = $post_array['whem'];

unset($post_array['whem']);

if($this->db->insert('customers',$post_data) === false)
{
return false;
}
else
{
$primary_key = $this->db->insert_id();
}

$whem_data = array(
"CF_C_id" => $primary_key,
"CF_name" => $CF_name
);

return $this->db->insert('customers_followers',$whem_data);
}


and as about the "invisible" field you don't need it anymore.

You just learned something more about grocery CRUD :)

wa7eedem
  • profile picture
  • Member

Posted 27 May 2012 - 10:09 AM

thank you web-johnny soooo much

its work prefects I just have to change

$post_data


to

$post_array



and every thing is OK


I always find something new in grocery CRUD and its greet library

thanks again .