Forum Moderators: coopster

Message Too Old, No Replies

Problem Posting an array from a form

         

Trevk2011

9:37 am on May 26, 2011 (gmt 0)

10+ Year Member



I have a form with the following drop down box
 <tr>
<td class="auto-style3" style="width: 190px">
<select id="citsroom[]" multiple="multiple" name="citsroom[]">
<option value="All Rooms">All Rooms
</option>
<option value="AP Lab 1">AP Lab 1
</option>
<option value="AP Lab 2">AP Lab 2
</option>
<option value="AP Lab 3">AP Lab 3
</option>
<option value="AP Lab 4">AP Lab 4
</option>
<option value="AP Lab 5">AP Lab 5
</option>
</select></td>
<td class="auto-style3">
<select id="fepsroom" multiple="multiple" name="fepsroom">
<option value="All Rooms">All Rooms
</option>
</select></td>
<td class="auto-style3">
<select id="fahsroom" multiple="multiple" name="fahsroom">
<option value="All Rooms">All Rooms
</option>
</select></td>
<td class="auto-style3">
<select id="fhmsroom" multiple="multiple" name="fhmsroom">
<option value="All Rooms">All Rooms
</option>
</select></td>
<td class="auto-style3">
<select id="fmlroom" multiple="multiple" name="fmlroom">
<option value="All Rooms">All Rooms
</option>
</select></td>
</tr>


And the following code trying to check the array is passing when multiple values are selected.

$citsroom = array();
$citsroom = $_REQUEST['citsroom'];
echo "<pre>";
var_dump($citsroom);
echo "</pre>";


How ever the only thing echo'd out is the first value you select no matter how many you select.

array(1) {
[0]=>
string(9) "All Rooms"
}


Any help would be greatly appriciated.

eta_carinae

9:49 pm on May 28, 2011 (gmt 0)

10+ Year Member



It works on my side

<?php
if ($_POST['1']=='1')
{
$citsroom = array();
$citsroom = $_REQUEST['citsroom'];
echo "<pre>";
var_dump($citsroom);
echo "</pre>";
}

?>
<form action="citroom.php" method="post">
<tr>
<td class="auto-style3" style="width: 190px">
<select id="citsroom[]" multiple="multiple" name="citsroom[]">
<option value="All Rooms">All Rooms
</option>
<option value="AP Lab 1">AP Lab 1
</option>
<option value="AP Lab 2">AP Lab 2
</option>
<option value="AP Lab 3">AP Lab 3
</option>
<option value="AP Lab 4">AP Lab 4
</option>
<option value="AP Lab 5">AP Lab 5
</option>
</select></td>
</tr><input type="hidden" name='1' value='1'></form>



I've selected AP Lab 2 and AP Lab 3, the output is
array(2) {
[0]=>
string(8) "AP Lab 2"
[1]=>
string(8) "AP Lab 3"
}