How to save checkbox in db?

hpeterse posted Dec 3, 2020 at 08:47
I'm rebuilding my Chronoforms v4 forms in Chronoforms v7. That's a major difference. The form-results are being stored into a db, but I'm having problems with saving checkboxes. The db-field is a varchar(255).
In Chronoforms v4 I needed to add a 'Handle arrays' action before storing data to a db. I can't find such an option in Chronoform v7. Runnig the form gives an error 1054. This is caused by the checkbox. Without it is runs good and the data is stored into the db.
How can I fix this?
Max_admin posted Dec 3, 2020 at 16:14
that error should be solved in the next update, but for now, you may add a "Data source" and set the field name to match the table field name, and the value to:
and the value type to "JSON Encode"
ChronoForms developer...
hpeterse posted Dec 3, 2020 at 16:58
Hi Max,
How do I add a "data source". I can't find anything at the advanced settings or behavior of the field. I can see there's a 'Save data' behavior, but I can't configure that.
Regards, Hans
Max_admin posted Dec 4, 2020 at 04:47
when do you need this working ? the new update should fix it without any changes, it's supposed to be ready this weekend!
ChronoForms developer...
hpeterse posted Dec 4, 2020 at 14:07
That will be soon enough Max, no hurry.
Max_admin posted Dec 4, 2020 at 14:51
ChronoForms developer...
hpeterse posted Dec 5, 2020 at 10:52
Hi Max,
Thanks for the CF7 update. This fixed the issue partially. The array is stored in the db, thats fine. However, the result is not quite correct.
I've got a checkbox with to possible options: (1) Zomerlid (2) Winterlid.
This is how it's stored in the db field:
It must be without the brackets ([ ]) and quotes (""). Is this something I can fix myself, or still a bug?
Regards, Hans
Max_admin posted Dec 5, 2020 at 14:43
that's the correct value, it's JSON encoded, you better leave it as it's now, because this makes it easier to read the values later as an array!
How do you preview the table data usually ?
ChronoForms developer...
hpeterse posted Dec 6, 2020 at 10:25
The form is used for new members to register. Usually I only to send the form-information in an e-mail to our secretary and store the data in case information got lost. After payment is done, I register the user as Community Builder-user, which automatically creates a Joomla-user. I'm trying to automate creation of a CB-user. In CB, this field is also a checkbox. The data is stored as:
When I use the format which is used in CF7, CB doesn't work correct and the information is display incorrect.
Max_admin posted Dec 22, 2020 at 01:21
You may customize the value using PHP or shortcodes, what is "|*|" in the value ?
ChronoForms developer...
hpeterse posted Dec 22, 2020 at 10:09
It's part of the array-delimiter. It's a multiple-checkbox field in Community Builder, which has four possible values. When I use all values, this is the result:
zomerlid|*|winterlid|*|erelid|*|niet-spelend lid
I'm struggeling with two modules (Chronoforms and Community Builder) who handles arrays differently while using the same db-table.
You helped me how to retrieve stored array results in an formfield, which works when its JSON-coded. But when it's stored in the format as mentioned above, I don't know how to use this in CF.
hpeterse posted Dec 22, 2020 at 16:24
I think I'm one step further. After the read-data action I've added a PHP-action, as suggested by Max.
I can use this statement to convert the data to a proper array-format:
explode("|*|", $this->get('gebruiker.cb_lidmaatschap'))
I've tested this code in the PHP-action:
$var = explode("|*|", $this->get('gebruiker.cb_lidmaatschap))
foreach ($var as $value) {
echo $value;
Then all values are displayed.
If I know how to get this result into a multi-checkbox formfield, I've got what I want.
hpeterse posted Dec 22, 2020 at 16:54
Got it. This is my solution:
$lidmaatschap = explode("|*|", $this->get('gebruiker.cb_lidmaatschap'));
$this->data('gebruiker.cb_lidmaatschap', $lidmaatschap, true);
You need to login to be able to post a reply. Inc. (Ohio, USA) is an authorized retailer for
goods and services provided by