2012-11-27 34 views
1

我試圖從下拉列表中捕獲多個選項並通過郵件發送它。 我試過下面的代碼。從下拉列表中捕獲多個選項

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";} 

請幫助我。

+0

您有什麼問題?我認爲你寫的代碼的唯一問題是$ thelist與數組是相同的變量。 –

回答

1
$thelist = $_POST['thelist']; 
if(is_array($thelist)){ 
    foreach($thelist as $item){ 
     echo $item.'<br>'; 
    } 
}else{ 
    echo 'thelist is not an array'; 
} 
1

變化thelist[]thelist,因爲你的命名不同,有不同的名稱醒目,這樣做:

<select name="thelist" multiple="multiple"> 
<option value="Value 1">Value 1</option> 
<option value="Value 2">Value 2</option> 
</select> 

和塞繆爾說:

$thelist = $_POST['thelist']; 
if(is_array($thelist)){ 
    foreach($thelist as $item){ 
    echo $item.'<br>'; 
    } 
}else{ 
    echo 'thelist is not an array'; 
} 
+0

爲我工作,但我需要在開始時圍繞'thelist'包括[] –

相關問題