Reputation: 11
I am trying to capture multiple options from a dropdown list and send it through mail. I have tried the following code.
HTML:
<select name="thelist[]" multiple="multiple">
<option value="Value 1">Value 1</option>
<option value="Value 2">Value 2</option>
</select>
PHP
if( is_array($thelist))
{
while (list ($thelist) = each ($thelist))
{
echo "$thelist <br>";
}
}
else{echo "not working";}
Please Help me out.
Upvotes: 1
Views: 1237
Reputation: 37846
change the thelist[]
to thelist
, because you are naming differently and catching with different name, do this:
<select name="thelist" multiple="multiple">
<option value="Value 1">Value 1</option>
<option value="Value 2">Value 2</option>
</select>
and as Samuel says:
$thelist = $_POST['thelist'];
if(is_array($thelist)){
foreach($thelist as $item){
echo $item.'<br>';
}
}else{
echo 'thelist is not an array';
}
Upvotes: 1
Reputation: 16828
$thelist = $_POST['thelist'];
if(is_array($thelist)){
foreach($thelist as $item){
echo $item.'<br>';
}
}else{
echo 'thelist is not an array';
}
Upvotes: 1