I'm trying to create something of a packing list that will export into an array that I can print out.
The basic code is as follows:
<form method='post' id='items' action='items.php'>
<input type="checkbox" name='list[]' value='sunglasses' />sunglasses
<input type='checkbox' name='list[]' value='sunblock' />sunblock
<input type='checkbox' name='list[]' value='socks' />Socks<input type="text" name="socks_qty">
<?php
if (isset($_POST['list'])) {
print_r($_POST['list']);
}
?>
Only items that are checked will appear in the array. I would like to add functionality that will allow me to specify a quantity of SOME items (ie. socks)with a text input field next to the checkbox so that I can extract the quantity from the array somehow. I'm not sure the best way to approach this as not all items need to have a quantity and I'm not sure how to tie the quantity to a specific item.
The output might be something like 'list[socks][3]'.
What would be the best way to approach something like this?
Aucun commentaire:
Enregistrer un commentaire