Editing checkbox array.

st stephenfsnow 25 Apr, 2013
I've run into a problem with editing a form that has an array of checkboxes. I'm using the following code so that the value is set to 0 if the checkbox is unchecked...
<td>
	<input type="hidden" name="day_28[0]" title="LEH" value="0"/>
	<input type="checkbox" name="day_28[0]" title="LEH" value="1"/>
</td>
<td>
	<input type="hidden" name="day_28[1]" title="BAT" value="0"/>
	<input type="checkbox" name="day_28[1]" title="BAT" value="1"/>
</td>
<td>
	<input type="hidden" name="day_28[2]" title="HYB" value="0"/>
	<input type="checkbox" name="day_28[2]" title="HYB" value="1"/>
</td>
<td>
	<input type="hidden" name="day_28[3]" title="ONE" value="0"/>
	<input type="checkbox" name="day_28[3]" title="ONE" value="1"/>
</td>
<td>
	<input type="hidden" name="day_28[4]" title="CAS" value="0"/>
	<input type="checkbox" name="day_28[4]" title="CAS" value="1"/>
</td>
<td>
	<input type="hidden" name="day_28[5]" title="MGS" value="0"/>
	<input type="checkbox" name="day_28[5]" title="MGS" value="1"/>
</td>
<td>
	<input type="hidden" name="day_28[6]" title="KGS" value="0"/>
	<input type="checkbox" name="day_28[6]" title="KGS" value="1"/>
</td>
<td>
	<input type="hidden" name="day_28[7]" title="PRR" value="0"/>
	<input type="checkbox" name="day_28[7]" title="PRR" value="1"/>
</td>
<td>
	<input type="hidden" name="day_28[8]" title="OIB" value="0"/>
	<input type="checkbox" name="day_28[8]" title="OIB" value="1"/>
</td>
<td>
	<input type="hidden" name="day_28[9]" title="IST" value="0"/>
	<input type="checkbox" name="day_28[9]" title="IST" value="1"/>
</td>
<td>
	<input type="hidden" name="day_28[10]" title="STB" value="0"/>
	<input type="checkbox" name="day_28[10]" title="STB" value="1"/>
</td>
<td>
	<input type="hidden" name="day_28[11]" title="TRP" value="0"/>
	<input type="checkbox" name="day_28[11]" title="TRP" value="1"/>
</td>
<td>
	<input type="hidden" name="day_28[12]" title="TEP" value="0"/>
	<input type="checkbox" name="day_28[12]" title="TEP" value="1"/>
</td>
<td>
	<input maxlength="50" size="15" type="text" name="day_28[13]" title="RigWell" value="none"/>
</td>


However, when using the DB Record Loader, if a checkbox had been checked, it sets the hidden value to '1' . This becomes a problem when the box is then unchecked as the DB Save action will save the value as '1' instead of '0' for an unchecked box.

<td>
	<input type="hidden" name="day_28[0]" title="LEH" value="1"/>
	<input type="checkbox" name="day_28[0]" title="LEH" value="1"/>
</td>
<td>
	<input type="hidden" name="day_28[1]" title="BAT" value="1"/>
	<input type="checkbox" name="day_28[1]" title="BAT" value="1"/>
</td>
<td>
	<input type="hidden" name="day_28[2]" title="HYB" value="1"/>
	<input type="checkbox" name="day_28[2]" title="HYB" value="2"/>
</td>

etc...


If I don't use the hidden fields, then nothing is saved for unchecked boxes and it obviously leads to the wrong boxes being checked on a DB Record Loader (since the arrays will no longer match up).

What am I missing here? Is there any way to tell the DB Record Loader not to fill hidden values?
st stephenfsnow 25 Apr, 2013
I tried using a script like this...

$(document).ready(function(){
    $('#day_28[0], #day_28[1], #day_28[2], #day_28[3], etc...').click(function(){
        $(this).val(this.checked ? 1 : 0);
    });
});


But it doesn't seem to work.
st stephenfsnow 26 Apr, 2013
Unfortunately this...

<?php
if($form->data['day_28[0]'] == null);
	{
	$form->data['day_28[0]'] = "0";
	}
?>


doesn't seem to work either.

I feel like there's gotta be a simple way to fix this... any help is greatly appreciated.🙂
Gr GreyHead 26 Apr, 2013
Hi stephefsnow,

ChronoForms uses an alt="ghost" attribute to mark inputs that shouldn't be republished. You could try adding this to your 'ghost' inputs. The attribute must be exactly as I posted it here with double quotes and no capital letters.

Bob
This topic is locked and no more replies can be posted.