⚠ 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

pass variable into add form?



jezeus
  • profile picture
  • Member

Posted 16 March 2012 - 03:02 AM

first of all, thanks for making gCRUD, it seems like an excellent project.

Is it at all possible to pass variables from one table into the add form for another?

As an example I have a table of sales leads. once I take care of the leads I want to click a button to convert them to a jobs table.

This function might give you a better idea of what I am trying to accomplish:


function leads()
{
/* This is only for the autocompletion */
$crud = new grocery_CRUD();
$crud->set_theme('datatables');
$crud->set_table('leads');
$crud->set_subject('Label Leads');
$crud->add_action('Add Job', '', '','ui-icon-image',array($this,'add_job'));

$output = $crud->render();

$this->_example_output($output);
}

function add_job($primary_key , $row)
{
return site_url('http://domain.com/index.php/crm/jobs/add/').'?company='.$row->company;
}



thank you!

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

Posted 16 March 2012 - 06:59 AM

As I understood, you can simply do it with the callback_edit_field ( http://www.grocerycrud.com/documentation/options_functions/callback_edit_field ). The second parameter is the $primary key so for now you will just have a quick query for example:


function edit_field_callback_1($value, $primary_key)
{
$this->db->where('id',$primary_key);
$lead = $this->db->get('leads')->row();
return "<a href='".site_url('http://domain.com/index.php/crm/jobs/add/').'?company='.$lead->company."'>add company</a>";
}


as for the field name you can have a fake field for example:


$crud->edit_fields('fristname',...,'add_company',....);


so you will just have the line:

$crud->callback_edit_field('add_company',array($this,edit_field_callback_1));


and everything will work OK.