can anyone help me about what code to use to process a form with multiple checkboxes, and display the "checked" boxes on the other screen...

i`ve used:

<?php
for ($x = 0; $x < count($dvd);$x++)
{
print $dvd. "<br>";
}

?>

but all it does is show the last "checked" box, not all selections..

thank you.

    Each checkbox should have it's own unique name on the from side and will come over to the second page as variables with the names of the input fields.
    Just check the variable names for the value you set in the <input> statement of the check boxes.

    -Mce

      Alternatively, give all the checkboxes the same name, and end that name with []. The result will be interpreted by PHP as an array. All the checkboxes will still need different values, of course, so that you can distinguish them in the resulting array.

      <input type="checkbox" name="setting[]" value="1">Setting One<br>
      <input type="checkbox" name="setting[]" value="2">Setting Two<br>
      etc.

        That's a good suggestion actually I often use something similar (tag a row id from a DB to the end of a checkbox name).

        -Mce

          The way I typically handle this is something like this.

          On the form page:

          $res=mysql_db_query(DBNAME,"select id, name from table");
          while($row=mysql_fetch_array($res)) {
          echo "<input type=checkbox name=\"id[".$row["id"]."]\" value=\"Y\">";
          }

          On the page submitted to:

          while(list($key,$value)=each($id)) {
          if($value=="Y") [do whatever you need here with the $key]
          }

          -Tim

            what about this same question for a multiple select listbox?

              Same answer(s). 'Course, just trying it would have been sufficient...

                TRY my friend?

                That might mean gasp reading doc!

                That being said, php.net is the BEST online information I have ever witnessed in my 22+ years of programming on the net. And I'm only 28 years old.

                -Tim

                  4 months later

                  RE: Grouped checkbox elements returned and processed as a comma-separated string.

                  Hey gang. I've been using the above method (array[]) for a few years now, but i just read here about Group Checkbox form elements that get processed as a comma-separated string...

                  By giving several checkboxes the same name attribute value, you create a group of checkbox elements. The browser automatically collects the values of a checkbox group and submits their selected values as a comma-separated string to the server, significantly easing server-side form processing.

                  This appears to be a standard HTML feature, the way that is written. Various other HTML help web sites say the same thing.

                  The reason i am so interested in this, is because the form i am constructing at the moment requires the grouped checkbox elements to be stored in the database as a comma separated string!

                  eg.

                  <br/><input type=checkbox name=shape value=square> square
                  <br/><input type=checkbox name=shape value=circle> circle
                  <br/><input type=checkbox name=shape value=triangle> triangle

                  if user ticks, say, square and triangle... then on return to form.php, you would assume (according to that quote) that the value of $shape would be "square,triangle"

                  However, no matter what i try, $shape for me is ALWAYS just simple the last checkbox that was ticked (ie. in this case $shape == "triangle")

                  Has anyone had experience in this area, or any suggestions? If i could get this to work it would cut down a lot of code that is reconstructing the array once the form is submitted.

                  Cheers.

                    Write a Reply...