Checkbox Group not saving correctly into database
Hi there
Having a wee problem with the result of a checkbox group entering as the word "Array" into database. I have tried imploding to comma seperate out the array and it worked but had issues exploding back in so we can check selections again for updating.
1. Why did the code generated by data assist for checkbox group not work in the first place
2. Do I need to hand code implode and explode to make it work.
3. If so please help with the explode
Here is my code (Used single checkbox data assist generated code and adapted it for array)
$UpdateQuery->bindColumn("FeaturesBox", "s", "".((isset($_POST["FeaturesBox"]))?implode(", ", $_POST["FeaturesBox"]):"") ."", "WA_BLANK");
<label class="checklabel" for="FeaturesBox"><input type="checkbox" name="FeaturesBox[]" id="FeaturesBox_1" value="1" class="formCheckboxField_Standard" <?php if (!(strcmp((isset($_GET["invalid"])?ValidatedField("Productupdate","FeaturesBox"):"". in_array("1", explode(", ", $WADAProduct_update->getColumnVal("FeaturesBox"))).""),"1"))) {echo "checked=\"checked\"";} ?> tabindex="1" title="Please enter a value.">No</label>
<label class="checklabel" for="FeaturesBox_2"><input type="checkbox" name="FeaturesBox[]" id="FeaturesBox_2" value="2" class="formCheckboxField_Standard" <?php if (!(strcmp((isset($_GET["invalid"])?ValidatedField("Productupdate","FeaturesBox"):"". in_array("2", explode(", ", $WADAProduct_update->getColumnVal("FeaturesBox"))).""),"2"))) {echo "checked=\"checked\"";} ?> tabindex="2" title="Please enter a value.">Yes</label>
Here is the original checkbox group data assist generated code (when executed it just has the words ARRAY in database)
$UpdateQuery->bindColumn("FeaturesBox", "s", "".((isset($_POST["FeaturesBox"]))?$_POST["FeaturesBox"]:"") ."", "WA_BLANK");
<label class="checkSublabel_Narrow" for="FeaturesBox__1">
yes <input type="checkbox" name="FeaturesBox[]" id="FeaturesBox__1" value="1" class="formCheckboxField_Standard" <?php if (array_search("1", ((isset($_GET["invalid"]) && ValidatedField("Productupdate2","FeaturesBox"))?ValidatedField("Productupdate2","FeaturesBox"):array())) !== false) {echo "checked=\"checked\"";} ?> tabindex="1" title="Please enter a value."></label>
<label class="checkSublabel_Narrow" for="FeaturesBox__2">
no <input type="checkbox" name="FeaturesBox[]" id="FeaturesBox__2" value="0" class="formCheckboxField_Standard" <?php if (array_search("0", ((isset($_GET["invalid"]) && ValidatedField("Productupdate2","FeaturesBox"))?ValidatedField("Productupdate2","FeaturesBox"):array())) !== false) {echo "checked=\"checked\"";} ?> tabindex="2"></label>