Jump to content


Field with a default value and field value

callback before insert crud default value

  • Please log in to reply
1 reply to this topic

#1 Dankof

Dankof

    Newbie

  • Members
  • Pip
  • 2 posts

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!

 

 

 



#2 Dankof

Dankof

    Newbie

  • Members
  • Pip
  • 2 posts

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! :)

 







Also tagged with one or more of these keywords: callback before insert, crud, default value

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users