Reputation: 1246
Somewhat new to php, I did some searching but didn't find a clear answer. I have a page with automatically generated checkboxes coming from a read CSV file:
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
$row++;
echo '<tr><td>' . $data[0] . '</td><td><input type="checkbox" name="included" value="col' . $row . '" /></td></tr>';
echo "<br>";
}
This form will submit to a page, and I want to get an array of the checked boxes, like "col2" "col4" "col5"
How do I do this?
Upvotes: 1
Views: 126
Reputation: 5882
You need to change the name of your checkbox to included[].
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
$row++;
echo '<tr><td>' . $data[0] . '</td><td><input type="checkbox" name="included[]" value="col' . $row . '" /></td></tr>';
echo "<br>";
}
And then read the checked list with $_POST['included']
(which will be an array).
Upvotes: 2
Reputation: 437584
Change the name
to name="included[]"
and you will get an array when the form is submitted.
Upvotes: 1