1

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?

4 Answers 4

2

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).

Sign up to request clarification or add additional context in comments.

Comments

1

Change the name to name="included[]" and you will get an array when the form is submitted.

Comments

1

Name your inputs included[].

Comments

0

Change the name from included to included[]

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.