I currently have two drop down menus where the second one is populated from the first one. My second drop down menu should be able to do multiple selection. I have searched online and found out how to do so (add in multiple and put brackets after name), but unfortunately when I retrieve the data on the next page, it seems that none of the selections were added to the variable array. On the other hand, it "POST"-ed the null value which is 1. My coding looks pretty much the same as everyone else's so I don't know why it doesn't work. Hopefully someone can shed some light. Thanks in advance. Here's my current coding.=)
Theres a lot of code before this but this is the form part.
-
// Get the posted data, if any, or initialize as null or today's date
-
($type = @$_POST['Type']) or $type = 1;
-
($item = @$_POST['Item']) or $item = 1;
-
($name = @$_POST['name']) or $name = null;
-
($firstdate = @$_POST['firstdate']) or $firstdate=date("ymd");
-
($lastdate = @$_POST['lastdate']) or $lastdate = date("ymd");
-
-
-
// Open the form element
-
echo '<form action="" method="post"> ';
-
echo '<p>User(Type username or all): <input type="text" name="name" value="', htmlentities($name),'"/><br//></p>';
-
echo '<p>Start of Period (yymmdd): <input type="text" name="firstdate" value="', htmlentities($firstdate),'"/><br//></p>';
-
echo '<p>End of Period(yymmdd): <input type="text" name="lastdate" value="', htmlentities($lastdate),'"/><br//></p>';
-
-
// Print first select
-
echo '<select name="Type" onchange="submit();">';
-
echo '<option value="">- All projects -</option>';
-
-
foreach(array_keys($items) as $_type) {
-
// Check if this type was selected last submit
-
$selected = ($type == $_type ? 'selected="selected"' : '');
-
-
// Print this type as an option
-
echo '<option value="'. $_type .'" '. $selected .'>'. $_type .'</option>';
-
}
-
echo '</select>';
-
-
// Print the second select
-
echo '<select multiple name="Item[]">';
-
echo '<option value="">- All phases -</option>';
-
if($type) {
-
foreach($items[$type] as $_item) {
-
// Check if this item was selected last submit
-
$selected = ($item == $_item ? 'selected="selected"' : '');
-
-
// Print this item as an option
-
echo '<option value="'. $_item .'" '. $selected .'>'. $_item .'</option>';
-
}
-
-
}
-
echo '</select>';
-
echo "<br><br>";
-
-
-
// Close the form element
-
echo '</form>';
-
-
//Do something with the selected items
-
$_SESSION['name'] = $name;
-
$_SESSION['type'] = $type;
-
$_SESSION['item'] = $item;
-
And on the next page, I do this to check what was in $item. (Again, this is just a snippet of my code)
-
<?php
-
//opens session
-
session_start();
-
$items=$_SESSION['items'];
-
print_r($item);
-
?>
-
Thanks again.