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.

linuxoid
 
JohntheFish replied on at Permalink Best Answer Reply
JohntheFish
The general approach of this howto still applies, but obviously needs to be revised for v8 best practice:
https://legacy-documentation.concrete5.org/tutorials/save-and-retrie...
linuxoid replied on at Permalink Reply
linuxoid
That's exactly what I need. Thanks a lot!
JohntheFish replied on at Permalink Reply
JohntheFish
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.
linuxoid replied on at Permalink Reply
linuxoid
What field type should I use in db.xml to store json encoded array?
JohntheFish replied on at Permalink Reply
JohntheFish
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.
linuxoid replied on at Permalink Reply
linuxoid
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?
linuxoid replied on at Permalink Reply
linuxoid
I've also checked this:
https://legacy-documentation.concrete5.org/tutorials/converting-json...

but it says:
Call to undefined method Controller::object_to_array()
linuxoid replied on at Permalink Reply
linuxoid
didn't notice it's a function I have to create. can't delete the post.
JohntheFish replied on at Permalink Reply
JohntheFish
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.