cougar23 Posted October 10, 2008 Share Posted October 10, 2008 I have a page that displays time slots people can sign up for by selecting checkboxes input elements. for the <input> tag values, the "name"'s are the same, and the values are the date and time values of the time slot. When I submit this form to the server (and have selected two or more checkboxes), only the most recently checked checkbox is coming through on my $_POST variable when it gets to the server. Here's the code I have on the page for the checkbox imput (this is inside of a loop that executes from a specified earliest time show to a latest time shown) echo '<input type="checkbox" name="timeSlot" value="'.$date.';'.$startTime.';'.$endTime.'">'; Then server side I want to view all the checkboxes selected //get the time slots the faculty member checked to be available for advising $selectedTimeSlots = $_POST['timeSlot']; echo $selectedTimeSlots; So, for example, if I selected three checkboxes for the date 2008-11-17, for the times 8:00 AM-8:30 AM, 8:30 AM-9:00 AM, 9:00 AM-9:30 AM, the output of the variable server-side ($_POST['timeSlots']) is only the 9:00 AM-9:30 AM slot. What am I doing wrong or how can I make the file do what I want to do, which is to have a collection of ALL the selected timeSlots? Thanks in advance Link to comment https://forums.phpfreaks.com/topic/127909-sending-multiple-checkbox-values-to-server-php/ Share on other sites More sharing options...
KevinM1 Posted October 10, 2008 Share Posted October 10, 2008 Change the name of all the checkbox inputs to timeSlots[]. This will pass the values to PHP as elements of an array. Then you can echo them all: foreach($_POST['timeSlots'] as $time) { echo "$time<br />"; } Link to comment https://forums.phpfreaks.com/topic/127909-sending-multiple-checkbox-values-to-server-php/#findComment-662196 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.