Home > money, programming > How to handle checkbox in PHP

How to handle checkbox in PHP

December 15th, 2009 admin Leave a comment Go to comments

Check box handling is bit different compared to other form objects because it can receive multiple values. Here is the HTML code for the form

1
2
<input type="checkbox" name="fruit[]" value="a" />Apple<br />
<input type="checkbox" name="fruit[]" value="o" />Orange<br />

and PHP code to handle the checkbox values.

1
2
3
4
5
6
7
8
9
$fruit = $_POST['fruit'];
  if(!empty($fruit)) 
  {
    foreach($fruit as $value)
    {
      echo($value);
      echo("<br />");
    }
  }
Categories: money, programming Tags: , ,
  1. No comments yet.
  1. No trackbacks yet.