Dynamic Checkbox Failing to load comma-separated values

My code is for a checkbox group whose multiple options selected in the form should be posted in a comma separated text format into one field marked varchar with enough room to store all options if selected.

If I use a dropdown list with a dynamic table source and the code is marked for multiple=“true” I get exactly the comma-separated insert behavior with no extra configuration required. A regular wappler insert query requires nothing special.

My database sees this as it should be :

But this checkbox set up the same way with a repeating dynamic options source (as my dropdown list form) requires extra steps. Right now I only get the last option’s text inserted into the table input.

Yet, the code, though not styled yet, shows the dynamic sourced values as the checkboxes as I want.

<div is="dmx-checkbox-group" id="get_gefuehl_vals" name="assoziierte_gefuehl_1" class="checkbox-group">
    <div id="repeat_assoziierte_gefuehl_1" is="dmx-repeat" dmx-bind:repeat="get_ukd_gefuehl_1.data.query_gefuehl_1_vals" dmx-on:update="">
        <label class="form-check-label"><input class="form-check-input" dmx-bind:id="$key" type="checkbox" name="gefuehl_1" dmx-bind:value="gefuehl_value.split(',')">{{gefuehl_value}}</label>

But the output of an insert request to the server is this –

Content-Disposition: form-data; name="gefuehl_1"

Content-Disposition: form-data; name="gefuehl_1"

Content-Disposition: form-data; name="gefuehl_1"


The answer must be staring me in the face.
When I use Developers tools Inspect the code Request shows each value selected but split into separate inserts with the same input name, instead of just one input name with all the values together separated by commas.

In order to send the checkbox values as an array to the server side their names must end with [] like name="mycheckbox[]"

I have tried that before but I am getting ERROR “Array to string conversion”

"#0 [internal function]: exception_error_handler(8, 'Array to string...', '/is/htdocs/wp12...', 139, Array)\n#1 /is/htdocs/wp12516289_VXRU2NWLJ9/www/myweburl.de/dmxConnectLib/lib/db/Connection.php(139): PDOStatement->bindParam(7, Array, 2)\n#2 /is/htdocs/wp12516289_VXRU2NWLJ9/www/myweburl.de.de/dmxConnectLib/modules/dbupdater.php(38): lib\\db\\Connection->execute('INSERT INTO `st...', Array, false

I think I really have to fix this in my INSERT server parameters for this table input “gefuehl_1”

The problem is in the internal looping repeat – the input name gets repeated over & over.
name="gefuehl_1[]" should only happen once, not multiple times itself.

You would need to use the join formatter to create the comma separated array for that insert this topic may help:

Here is the code that works perfectly when I “simply” set up a List selector. It allows multiple lines/options to be selected. I believe @Teodor supplied this months ago

The input box below immediately confirms the 3 selections. However, this requires using a key to be depressed as the mouse moves for each selection.
Not as user-friendly as a simple multiple checkbox group only needing a mouse.

This is the code for the List selector view – I just can’t get this code re-written to achieve the same comma-separated multiple text string as the list selector.

<div class="mb-3">
<label for="inp_assoziierte_gefuehl_2">Assoziierte gefuehl 1</label>
<select id="select11" class="form-select form-control-lg" dmx-bind:options="get_ukd_gefuehl_1.data.query_gefuehl_1_vals" optiontext="gefuehl_value" name="gefuehl_1" optionvalue="gefuehl_value.split(',')" multiple="true"> </select>
 <input type="text" class="form-control" id="inp_assoziierte_gefuehl_1" name="gefuehl_1" dmx-bind:value="select11.value">

I was looking at this Documentation to give me some understanding how to work with arrays. This tutorial chose to use tags as the example.

My Request for ALL Tutorials is to finish with the CODE that all of the clicking steps produced.

When something doesn’t work after a tutorial is tried the usual request is to post the CODE first.

That is why all tutorials should do the same. Show the resulting working code at the end of the tutorial.
Please . . :thinking:

One way to do this is a hidden input the other is as teodor said the brackes to create an array

method 1 (a hidden input) you’ll need to add your binds as I only used yours as a template:

<div is="dmx-checkbox-group" id="get_gefuehl_vals" name="assoziierte_gefuehl_1" class="checkbox-group">
     <div id="repeat_assoziierte_gefuehl_1" is="dmx-repeat" dmx-bind:repeat="get_joined_communities.data.repeat_communities">
        <div class="form-check mr-0 form-check-inline">
            <input class="form-check-input" type="checkbox" id="checkbox_enter_id" checked name="somename[]" dmx-bind:value="name">&nbsp;
            <label class="form-check-label" for="checkbox_enter_id">{{name}}</label>

<input id="text2" name="text2" type="text" class="form-control" dmx-bind:value="get_gefuehl_vals.value">

Method 2 as teodor said using a name on the checkboxes like check[]
Then if you use $_POST.check.join(',') on the insert/update it will input a comma seperated array

I’ve posted now several times why the brackets (which is how I always processed multiple choice checkboxes for the past couple of decades) will not work.

The way that method works is if the checkbox group is hard-coded.

Using the looping method I have been using just never will hold the array of selected values cumulatively.
Trust me.

I am going to have to abandon this whole thing and go back to hard-code.

But thank you for your time and help!

I have tested this and it worked for me but also I offered two solutions why will the hidden input not work?

You can see from the code I posted above my checkboxes are also repeated maybe I didn’t understand your wanted outcome