I am trying to build a form that lists all available items and users can select some items and enter a value to input element aside the checkbox.
Each checkbox has a input text box aside it.
<?php
foreach ($items as $item):
$itemID = $item['item_id'];
$itemTitle = $item['item'];
?>
<tr>
<td>
<li>
<div class="checkbox">
<input type="hidden" name="selected_items[]" value="0">
<input type='checkbox' name='selected_items[]' value='<?php echo $itemID; ?>'/>
<?php echo ucfirst($itemTitle); ?>
</div>
</li>
</td>
<td><input type='number' name='quantities[]' value="0.00" step="0.01" /> </td>
</tr>
<?php endforeach; ?>
Here's how the form looks:
Available Items | Qty
--------------------------
[] Bread | [input]
[] Coffee | [input]
[] Egg | [input]
[] Cake | [input]
I want the two arrays : selected_items[]
and quantities
to be of the same length as they are so I can combine them.
If unchecked, value should be left to 0.
So, combined_array should look like:
0=>0
Coffee=>44
Egg=>56
0=>0
Can anyone help me with this?
Aucun commentaire:
Enregistrer un commentaire