Buy Now
Sign in

Save a checkbox group to a field in a database

FransO , April 27 2017, 13:55
F
FransO 19
April 27 2017, 13:55 #367503
I have seen in a post that it is possible to use something like checkboxlist:{data: join checkboxes} in the data override of the DBsave to convert checkbox group to a comma separated string and store that in a database. However I cannot find that post any more. Can anyone show me the correct syntax or the place where this syntax is defined?
admin 30
April 27 2017, 14:18 #367509
Hi FransO,

in the data override box:
table_field_name:{data/join:checkboxes_field_name}

and better you json_encode it:
table_field_name:{data/jsonen:checkboxes_field_name}


Best regards,
Max
F
FransO 19
April 27 2017, 15:02 #367518
Thanks, Max. I knew I had seen something like that but could not find it again.

I tried it, but I get "{data" as the value in the database field. Looks like it stops reading at the / and then considers it plain text.
My data overrides are:
created:{date:Y-m-d H:i:s}
maanden:{data/jsonen:maanden}

The result is:
[option] => com_chronoforms6
[chronoform] => Test form
[event] => submit
[email] => a@b.nl
[naam] => ab
[adres] =>
[postcode] =>
[woonplaats] =>
[toezegging] => 0
[termijnen] => 1
[termijnbedrag] => 0
[maanden] => {data
[betaalwijze] =>
[iban] =>
[iban_tnv] =>
[opmerkingen] =>
[submit_form] =>
[maanden_list] => 0
[created] => 2017-04-27 16:59:35

Regards,

Frans
F
FransO 19
April 27 2017, 18:37 #367525
 Answer
Hi Max,

I solved it for now by adding a php action to the submit that implodes the checkboxes group to a hidden variable and using that hidden variable to fill the database field. The data/join construct would have been more elegant. If you find a solution to make the data/join working, please let me know.

Regards,

Frans
admin 30
April 28 2017, 08:56 #367544
Hi Frans,

I have fixed this issue and it should be available in the next update, but let me know if you need an early access to the patch file.

Best regards,
Max
F
FransO 19
April 28 2017, 09:14 #367545
Hi Max,

I can live with the work-around and will update the code as soon as the new update is out.

Thanks,

Frans
X
xoles 18
May 13 2017, 01:16 #368112
Hi, I'm using
table_field_name:{data/join:checkboxes_field_name}
to save a multiple selection checkbox, and works fine. But how to load that back to the checkbox in an update form? All other input fields load correctly, but the checkbox one. Thanks!
admin 30
May 13 2017, 01:31 #368115
Hi xoles,

If you save it using jsonen instead of join:

table_field_name:{data/jsonen:checkboxes_field_name}

which is the better way, then you can add this in the "special fields" section of the "Read data":

checkboxes_field_name/json

Best regards,
Max
admin 30
May 13 2017, 01:32 #368117
Another way which "may" work is to add this in the "selected values" box of the "checkboxes":

{data/split:checkboxes_field_name}

Best regards,
Max
X
xoles 18
May 13 2017, 01:39 #368119
The first option using jsonen worked great! Now it loads correctly. I have two forms, one for the first time the user fills the form and another one for updating their records.

On both forms, I use the squared brackets to indicate an array. Now, when saving an update, it crashes with this error:

Unknown column 'Array' in 'field list'

If I remove the squared brackets from the update form, it won't crash but only saves to db the last checked option.

Please advise.
admin 30
May 13 2017, 01:42 #368122
Do you have the same line below in the "update data override":
table_field_name:{data/jsonen:checkboxes_field_name}

?

Best regards,
Max
X
xoles 18
May 13 2017, 01:53 #368125
Yes, please find attached. Checkbox field has squared brackets.

==== EDITED =====

Sorry for the screenshot (please delete it ), brain is tired. Thanks for the help, it is working great!
Attachments
Screen_Shot_2017-05-12_at_4.51.34_PM.png
Screen_Shot_2017-05-12_at_4.51.34_PM.png
(175.53 KiB)
788 Downloads/Views