It looks like you're new here. If you want to get involved, click one of these buttons!
how can i have options separated by 'fieldsets' ?
$fields['related_entries']= array(
'type' => 'array',
'mode' => 'multi',
'options' => array(1 => 'Test one', 2 => 'Test Two', 3 => 'Test Three'),
'value' => array(2, 3)
);
$fields['related_entries']= array(but that won't work... any clues?
'type' => 'array',
'mode' => 'multi',
'options' => array(
'A' => array(1 => 'Test one', 2 => 'Test Two', 3 => 'Test Three'),
'B' => array(1 => 'Test one', 2 => 'Test Two', 3 => 'Test Three')
),
'value' => array(2, 3)
);
Comments
Hi both, I am having problem storing multi field into database. I am getting error: Message: Array to string conversion
`
`
I would like to save it as JSON if possible. And how can I than Edit this field afterwards if needed?
Thanks!
Update: I have managed to save data as JSON by using this below in on_before_save
Now just have to reverse the process on editing, populate multi field back. If you can help with that Thanks
I think what you want is the
serialized_fields
on your model:https://docs.getfuelcms.com/libraries/my_model
This is a property on the model that you can specify one or more fields in your model (in an array) that get serialized and deserialized upon retrieval. The default serialization method is JSON.
That actually sound good. What I am doing is fetching data with query form one of the tables and populating multi list. I am basically extending Fuel_users_model with few more fields.
Function inside Fuel_users_model.php:
Than inside public function form_fields I am using this below:
And inside on_before_save($values) function I use this below to prepare data:
This saves data into DB and that is fine. Last thing to figure out is how to (on user edit) retrive saved multi field data and display it in the right pane where selected items are.
I don't really know how to use serialized_fields.
Thanks, serialized_fields sorted things. It's super easy to use it. Thanks a lot