⚠ 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

how to set default value to hidden field



irshadjan
  • profile picture
  • Member

Posted 04 August 2019 - 15:07 PM

May i know how can i set default value for hidden fields since i am using fieldType('fieldname','hidden','my default value') but its not working value is not update which i pass as third parameter to this function. I am using the latest version of Grocery Crud enterprise Grocery CRUD Enterprise v2.7.9

 

 


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

Posted 13 August 2019 - 15:50 PM

May i know how can i set default value for hidden fields since i am using fieldType('fieldname','hidden','my default value') but its not working value is not update which i pass as third parameter to this function. I am using the latest version of Grocery Crud enterprise Grocery CRUD Enterprise v2.7.9

 

Hello @

 

You should use the function: callbackEditForm (https://www.grocerycrud.com/enterprise/api-and-function-list/callbackEditForm/) in order to achieve that. More specifically in your case you will do something like this:

$defaultValues = function ($data) {
    $data['fieldname'] = 'my default value';

    return $data;
};
$crud->fieldType('fieldname','hidden','my default value');
$crud->callbackAddForm($defaultValues);
$crud->callbackEditForm($defaultValues);


Let me know if that worked for you

 

Regards

Johnny