My form has both a text area and check boxes. When I POST the results, only one of the check box values gets posted, even if more than one is selected.
This is my form:
<form action="search.php">
<input type="text" name="term">
<input type="checkbox" name="filter" value="subject"> Subject
<input type="checkbox" name="filter" value="course"> Course
<input type="checkbox" name="filter" value="professor"> Professor
<input type="submit" name="submit" value="Go" />
And this is how I echo the form (search.php):
<?php
$term = $_GET['term'];
$filter = $_GET['filter'];
echo "$term $filter";
?>
The trouble is the names you have assigned each checkbox, what is happening currently is the first checkbox is being read by the PHP and its value assigned to the variable, the next filter checkbox is being read but then overwriting the currently assigned value of the variable, and then again with the 3rd checkbox. So you’ll always only ever get the last ticked checkbox as your value for the $filter variable.
You need to individually assigned each checkbox with a different name for example:
Then the PHP:
You also had your last checkbox’s value the same as the second so I changed the value from course to professor, if this is in fact wrong, you can obviously change it back.
Another note, it may also be a good idea to use the method POST instead of GET as it’s more secure, however, you may have reasons to be using GET, but it’s just a heads up 🙂