2012-11-15 45 views
0

在使用括號表示法之前,我將元素分組在一起,但我必須忽略某些內容。也許另一雙眼睛(或成千上萬)可以發現爲什麼這是回火。HTML分組輸入返回'數組',而不是PHP中的值的數組

foreach ($record as $field => $value) { 

if(strpos($value , '~') !== FALSE){ //All drop down lists are separated by ~ 
    $rows_of_dlist .= '<tr>'; 

$stored_field = explode ("mlljx", $value); 
$stored_field [0] = trim ($stored_field [0]); //Title of the list 
$stored_field [1] = trim ($stored_field [1]); //Values of the list 


$dlist = explode ('~', $stored_field [1]); 

foreach ($dlist as $dlist) { 
    $list_values .= " <td><input type='checkbox' name='selected_option[]'value='$dlist'/> &nbsp; $dlist</td>"; 
} 

$rows_of_dlist .= "<td align = 'center'>$stored_field[0]</td> $list_values</tr>"; 


<form id="all" name="all" method="POST" action="$page_name?page_view=report" > 
    <table align="center" width = "100%" border = "2"> 
     <th colspan = "1">Name Of Custom Drop-down List</th> 
     <th colspan = "10">Drop-list Values</th> 
     $rows_of_dlist  
     <tr> 
      <td align = 'center' colspan='10'> 
         <input type="submit" value="Make PDF" name = "make_pdf"/> 
      </td> 
     </tr> 
    </table> 
</form> 

值被公佈後,我考了POST數組:

var_dump($_POST); 
    exit; 

於是說$_POST['selected_option']是「數組」即使我選擇只有一個框。

+0

什麼是生成的HTML源(提交表單)? – Jocelyn

+0

在name ='selected_option []'和value ='$ dlist'/>之間是否需要空格? –

+0

如果我理解正確的HTML是什麼已經發布。我們使用模板,因此我會在變量中調整表單的形式,並且魔術會發生在後臺。我動態地構建表格。它是一個非常簡單的頁面,這就是爲什麼這使我瘋狂。 不幸的是,空間並沒有解決它,但很好的抓住。 – user1193752

回答

1

我覺得這個錯誤:

foreach ($dlist as $dlist) { 

它不應該是這樣的

foreach ($dlist as $element) { ... do something with each $element ... } 
+0

是啊,或者*除了'$ dlist'之外的任何* ... foreach($ array as $ array){echo $ array; ''以心痛結束。 – Norguard

+0

可悲的是,沒有解決這個問題,但我需要打破這種習慣。 – user1193752