⚠ 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

Field with a default value and field value



Dankof
  • profile picture
  • Member

Posted 18 November 2017 - 09:15 AM

Hello all,

I'm trying to create a field with a default value + Value of another field + Date of insert
 

Example of ID: IDPeter17112017
 

So, this is the code I have but it doesn't work, or maybe isn't the best way to do it.

 

$crud->add_fields('name','email','date');
$crud->callback_before_insert(function ($post_array) {
$name = $name['name'];
$date = $date['date'];

if (empty($post_array['id'])) {
$post_array['id'] = 'ID' . $name . $date;
}

return $post_array;
});


Any suggestions?

Thank you in advance!

 

 

 


Dankof
  • profile picture
  • Member

Posted 18 November 2017 - 09:59 AM

Aboslutely doing it wrong. I need to use "Callback_column" for this.

This is what I did and it works like a charm:


 

    $crud->add_fields('name','email','date');
    $crud->callback_column('id',array($this,'id_callback'));
    $output = $crud->render();
    function id_callback($value, $row)
    {
    return "ID" . $row->name . $row->date;
    }



Thank you! :)