How to save data from table of input text fields?
Permalink
I have a table of input text fields in the add block form. How can I save all that data in the block's DB by table rows (array or arrays or else?):
- what do I do in the save()?
- what do I put in the db.xml?
Thank you.
- what do I do in the save()?
- what do I put in the db.xml?
Thank you.
That's exactly what I need. Thanks a lot!
json is more secure than serialize/unserialize. There are hacks that can break in via a serialize of data that has not been sanitized first.
What field type should I use in db.xml to store json encoded array?
Depends on how big a list you want to save. If its only a few items and limited by the edit dialog, then calculate the maximum length and use a string. If its unrestricted, a text field.
It's a table, that is an array or arrays, and can be anything from 1 row to tens or hundreds of rows.
What about type 'json_array'? Is it used in C5?
What about type 'json_array'? Is it used in C5?
I've also checked this:
https://legacy-documentation.concrete5.org/tutorials/converting-json...
but it says:
Call to undefined method Controller::object_to_array()
https://legacy-documentation.concrete5.org/tutorials/converting-json...
but it says:
Call to undefined method Controller::object_to_array()
didn't notice it's a function I have to create. can't delete the post.
You don't need that tutorial any more. It was for an old core version where the json helper returned an object rather than an associative array. Now you just pass 'true' as a second parameter and it returns an array.
https://legacy-documentation.concrete5.org/tutorials/save-and-retrie...