0

我的 PHP 邮件表单中有两个单独的数组,它们是不同的复选框集:webdetailsgraphicsdetails。只会填写一组(除非选择了以前的单选按钮,否则另一组将被隐藏。)我想知道如何在我的 PHP 中正确引用它们。

这是我以前发布的一个,但不是两个:

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

如何在其中添加图形细节?复制代码段给我警告:为 foreach() 提供的参数无效

我不知道比这更多的PHP,因此将不胜感激。

--

这是我遇到错误的PHP:

<?php
/* Set mail headers */
$myemail  = "my.email@gmail.com";
$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:

<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:

<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" />
4

1 回答 1

4

它看起来不错,所以我猜是这样的:

复选框如果没有被选中就不会被发布,你需要检查有没有

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

少写

于 2013-01-12T23:58:39.447 回答