Hi i have a form that looks like this:
<div class="row calc">
<div class="large 12 columns">
<div class="large-1 columns">
<label>Quantity</label>
<input name="units[]" type="text" value="1">
</div>
<div class="large-1 columns">
<label>GroupNR</label>
<input name="article_group[]" type="text" value="2401">
</div>
<div class="large-2 columns">
<label>Item name</label>
<input name="article[]" type="text" value="Item 1">
</div>
<div class="large-3 columns">
<label>Description</label>
<input name="description_en[]" type="text" value="Description 1">
</div>
<div class="large-1 columns">
<label>Price/Unit</label>
<input name="unit_price[]" type="text" value="15500">
</div>
<div class="large-1 columns">
<label>Discount</label>
<input max="100" min="0" name="discount[]" type="number" value="0">
</div>
<div class="large-1 columns">
<label>Invoice</label>
<input checked="checked" name="invoice[]" type="checkbox">
</div>
<div class="large-1 columns">
<label>D. Note</label>
<input checked="checked" name="delivery_note[]" type="checkbox">
</div>
<div class="large-1 columns">
<label>Delete</label>
<a class="alert button tiny" onclick="$(this).closest('.calc').remove(); $( '#itemForm' ).trigger('change');">X</a>
</div>
</div>
These inputs get added dynamically (with Jquery) as rows, and there could be one or there could be 10, 20 you name it.
The problem is that when i submit these to php, i have no way of knowing which rows have the "invoice" and "D.note" checkboxes checked or unchecked, because the array i'm recieving looks like this
array:13 [▼
"units" => array:3 [▼
0 => "1"
1 => "1"
2 => "1"
]
"article_group" => array:3 [▼
0 => "2401"
1 => "2201"
2 => "2503"
]
"article" => array:3 [▶]
"description_en" => array:3 [▶]
"unit_price" => array:3 [▶]
"discount" => array:3 [▶]
"invoice" => array:2 [▼
0 => "on"
1 => "on"
]
"delivery_note" => array:2 [▼
0 => "on"
1 => "on"
]
]
But really, it is row "0" and "2" that are checked, and row "1" unchecked.
This is how i iterate through it in php/laravel
for($i=0;$i<count($items['units']);$i++){
$bookdetails = new BookingDetails;
$bookdetails->article_group = $items['article_group'][$i];
$bookdetails->article = $items['article'][$i];
$bookdetails->description_en = $items['description_en'][$i];
$bookdetails->units = $items['units'][$i];
$bookdetails->unit_price = $items['unit_price'][$i];
$bookdetails->discount = $items['discount'][$i];
$bookdetails->show_invoice = $items['invoice'][$i];
$bookdetails->show_picklist = $items['delivery_note'][$i];
$bookdetails->save();
}
So is there a way to submit the unchecked boxes aswell? Having a hidden input with the same name wont work since i use array without set index, maybe i can make my ajax call send a number to index the array, but there has to be a easier solution
Or does anyone have a suggestion for another solution?
Regards Johan