Hey guys,
I've got a set of checkboxes in the edit template in the admin config:
If I check one of these boxes and click apply everything is fine; however, when I unclick a box it does not update the database. I'm guessing that this is because unchecking doesn't set the value to '' or NULL. I'd prefer to leave it as a checkbox if possible as I think it is more user friendly, but if not possible I'm open to other ideas. Any ideas?
Thanks!
I've got a set of checkboxes in the edit template in the admin config:
<div class="field">
<label class="lbl150" for="msisType"><strong>MSIS:</strong></label>
<input type="checkbox" name="msisCore" value="Core" id="msisCore" />
Core
<input type="checkbox" name="msisCoreOption" value="Core Option" id="msisCoreOption" />
Core Option
<input type="checkbox" name="msisElective" value="Elective" id="msisElective" />
Elective
</div>
If I check one of these boxes and click apply everything is fine; however, when I unclick a box it does not update the database. I'm guessing that this is because unchecking doesn't set the value to '' or NULL. I'd prefer to leave it as a checkbox if possible as I think it is more user friendly, but if not possible I'm open to other ideas. Any ideas?
Thanks!
I ended up replacing the check boxes with radio toggles, adding a second toggle for the negative value:
<div class="field">
<label class="lbl150" for="msisType"><strong>MSIS:</strong></label><br />
<div style="float: left; width: 100px;">Core:</div>
<div style="float: left; width: 200px;">
<input type="radio" name="msisCore" value="Core" id="mbaCore">Yes
<input type="radio" name="msisCore" value="" id="mbaCore">No
</div>
<div style="clear: both;"></div>
<div style="float: left; width: 100px;">Core Option:</div>
<div style="float: left; width: 200px;">
<input type="radio" name="msisCoreOptionn" value="Core Option" id="mbaCoreOption">Yes
<input type="radio" name="msisCoreOption" value="" id="mbaCoreOption">No
</div>
<div style="clear: both;"></div>
<div style="float: left; width: 100px;">Elective:</div>
<div style="float: left; width: 200px;">
<input type="radio" name="msisElective" value="Elective" id="mbaElective">Yes
<input type="radio" name="msisElective" value="" id="mbaElective">No
</div>
<div style="clear: both;"></div>
</div>>
Hi redrings,
An unchecked checkbox will return a null or '' value in the result.
Bob
An unchecked checkbox will return a null or '' value in the result.
Bob
Hi redrings,
An unchecked checkbox will return a null or '' value in the result.
Bob
That doesn't seem to be the case in the Admin Config, unchecking a box and saving makes no change for me - the previous value remains.
Hi redrings,
Apologies, I'm wrong. No time to double check now. I think that if it's a single entry then there will be nothing in the $_POST array so the value will go unchanged; if it's part of a checkbox array then the array will be in the $_POST array but any unchecked entries will be blank or missing - I forget which.
Last time I had this problem I think I got round it be creating a $field_array and merged the $_POST array with it so that I knew every field was in the array I used to post to the database.
Bob
Apologies, I'm wrong. No time to double check now. I think that if it's a single entry then there will be nothing in the $_POST array so the value will go unchanged; if it's part of a checkbox array then the array will be in the $_POST array but any unchecked entries will be blank or missing - I forget which.
Last time I had this problem I think I got round it be creating a $field_array and merged the $_POST array with it so that I knew every field was in the array I used to post to the database.
Bob
Hi redrings,
Apologies, I'm wrong. No time to double check now. I think that if it's a single entry then there will be nothing in the $_POST array so the value will go unchanged; if it's part of a checkbox array then the array will be in the $_POST array but any unchecked entries will be blank or missing - I forget which.
Last time I had this problem I think I got round it be creating a $field_array and merged the $_POST array with it so that I knew every field was in the array I used to post to the database.
Bob
Thanks Bob - I'll give that a shot. I've never thought of putting the checkboxes in an array.
This topic is locked and no more replies can be posted.