⚠ 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 pass variable to hidden field?



elfuego1
  • profile picture
  • Member

Posted 04 March 2013 - 01:35 AM

Hello,

 

I want to add hidden fields to my form. The fields are not in a database.

Fields test1, test2 and test3 should have a value from an array which is available in controller.

Can you please tell me how to pass value for $value variable in callback_test1?

 

$crud->fields('title','category','test1','test2','test3');
$crud->callback_field('test1',array($this,'callback_test1'));

function callback_test1($value, $primary_key) {

  return "<input type='hidden' name='test1' value=".$value['value_for_test1']." id='test1'/>";
}

 

What should I do so there is value in hidden filed?

 

Thank you in advance.


Masmuh Vítězství
  • profile picture
  • Member

Posted 04 March 2013 - 05:17 AM

read documentation :

 

http://www.grocerycrud.com/documentation/options_functions/field_type


elfuego1
  • profile picture
  • Member

Posted 04 March 2013 - 05:58 AM

Ha. If it only was that simple... I wouldn't be asking.

 

Setting value like THAT:

 

$crud->field_type('test1', 'hidden', $test1);

 

works, if you select field from a database. Unfortunatelly I don't select these (test1, test2 and test3) fields from DB, so how do I set their values?

I know that for fields outside of database I should use "callback_field", but how do I pass a value to that method?


davidoster
  • profile picture
  • Member

Posted 04 March 2013 - 10:28 AM

Use the fields function to add your field.


elfuego1
  • profile picture
  • Member

Posted 04 March 2013 - 16:47 PM

Had anyone tried to add hidden field with value that is not selected from database or am I the only one?

 

I already use "fields" method.

If I add field as you suggest - without using callback_field - I get an error:

 

Severity: Notice

Message: Undefined property: stdClass::$extras

Filename: libraries/grocery_crud.php

Line Number: 2026