2013-01-12 117 views
0

我有兩個單獨的數組,我的PHP郵件格式是不同的複選框組:網絡細節graphicdetails。只有一組將被填寫(另一個將被隱藏,除非選擇了前一個單選按鈕。)我想​​知道如何在PHP中正確引用它們。組合兩個單獨的數組

這是我用來獲取一個發佈,但不是兩個:

foreach($_POST['webdetails'] as $value1) { 
    $webdetails_msg .= "$value1\n"; 
} 

我怎麼在裏面添加graphicdetails?複製的片段讓我警告:()提供的foreach無效參數

我不知道遠不止此PHP,這樣的解釋,將不勝感激。

-

這裏的PHP我得到一個錯誤有:

<?php 
/* Set mail headers */ 
$myemail = "[email protected]"; 
$subject = "New Request"; 

$webdetails   = $_POST['webdetails']; 
$graphicdetails  = $_POST['graphicdetails']; 

foreach($_POST['webdetails'] as $value1) { 
    $webdetails_msg .= "$value1\n"; 
} 
foreach($_POST['graphicdetails'] as $value2) { 
    $graphicdetails_msg .= "$value2\n"; 
} 

/* Let's prepare the message for the e-mail */ 
$message = " 
Details: 
$webdetails_msg 
$graphicdetails_msg 
"; 

/* Send the message using mail() function */ 
mail($myemail, $subject, $message); 

<?php exit(); } ?> 

HTML爲webdetails:

<input type="checkbox" name="webdetails[ ]" id="design" value="Design" /> 
<input type="checkbox" name="webdetails[ ]" id="development" value="Development" /> 
<input type="checkbox" name="webdetails[ ]" id="web-updates" value="Web Updates" /> 
<input type="checkbox" name="webdetails[ ]" id="forum-template" value="Forum Template (Full)" /> 
<input type="checkbox" name="webdetails[ ]" id="forum-graphics" value="Forum Graphics" /> 
<input type="checkbox" name="webdetails[ ]" id="web-other" value="Other" /> 

HTML爲graphicdetails:

<input type="checkbox" name="graphicdetails[ ]" id="graphic-logo" value="Logo Design" /> 
<input type="checkbox" name="graphicdetails[ ]" id="graphic-social" value="Social Media Graphics" /> 
<input type="checkbox" name="graphicdetails[ ]" id="graphic-other" value="Other" /> 
+0

是否所有''在同一'

'? – Martin

+0

是的,都一樣。 –

回答

4

它看起來很好,所以我猜測NG那就是:

複選框沒有得到公佈,如果不檢查他們,你需要檢查有任何

if (isset($_POST['graphicdetails'])){ 
    foreach($_POST['graphicdetails'] as $value1) { 
     $webdetails_msg .= "$value1\n"; 
    } 
} 

但在任何情況下

if (isset($_POST['graphicdetails'])){ 
    $webdetails_msg .= implode("\n", $_POST['graphicdetails'])."\n"; 
} // you don't need the curly braces for 1 line but SO has a small code width 

少寫

+0

這樣做。謝謝! –