强制发布复选框数组输入/解决方法

Sorry for the bad title.. I am trying to figure out a workaround to this fairly simple problem I am having.

HTML

<input type="text" name="test[description][]" / >
<input type="checkbox" name="test[confirm][]" value="1" / >

The html can be cloned by jquery..the problem I am having is that the checkbox wont post unless it's checked (this is what it's supposed to do I know). This messes up my PHP to check the checkbox index to see if it's checked.. if you clone this 3 times then leave the middle checkbox unchecked..but check the first and last.. the last checkbox gets index of 2 when it want it to be 3.

any suggestions are appreciated thank you.

I don't think you can do it the way you're trying to do it. There's no way to differentiate which checkboxes were checked as written. You can either:

1) Encode the position in the element name.

2) Create hidden fields, which will be sent, to record the checked/unchecked value. Initialize with something like:

<input id="hidden-1" type="hidden" name="test[description][]" value="0" />
<input id="check-1" type="checkbox" />
<script>
   $('#check-1').click(function() {
      var $hidden = $('#hidden-1');
      $hidden.val(hidden.val() == 0 ? 1 : 0);
   }
</script>

If the number is dynamic, you could encapsulate all that to generate the bindings dynamically as well.