I am trying to create a bunch of checkboxes dynamically from Php array, and show them in a foreach loop. Now I have checked, there is an option to use name="chk[]" array and foreach to select the checked stuff from the results. However I use bootstrap, and looks like the label gets crazy with this naming. I have a few other solutions I could use but they are not so elegant as this. Is there a way to use the array name and bootstrap both? Or another elegant solution? Fiddle here: https://jsfiddle.net/dgloria/dmr517jv/7/
<input type="checkbox" class="custom-control-input" id="chk[]" name="chk[]" value="One"><br>
<label class="custom-control-label" for="chk[]">One</label>
<input type="checkbox" class="custom-control-input" id="chk[]" name="chk[]" value="two"><br>
<label class="custom-control-label" for="chk[]">Two</label>
</div>
My other solution would be this
name="chk<?= $array['id'] ?>"
but then I need to do a query again to see what was in $array, when processing the results, and I would like to avoid that.
Aucun commentaire:
Enregistrer un commentaire