这是我的HTML:
<tr>
<td valign="left"><p>Please check all items needed *</p>
<p class="style2">(Default order will be one of each checked item unless otherwise indicated in the comments section.)</p>
<td valign="top">
<div align="left">
<input type="checkbox" name="supplies[]" value="black_toner" /> Black Toner<br />
<input type="checkbox" name="supplies[]" value="cyan_toner" /> Cyan Toner<br />
<input type="checkbox" name="supplies[]" value="magenta_toner" /> Magenta Toner<br />
<input type="checkbox" name="supplies[]" value="yellow_toner" /> Yellow Toner<br />
<input type="checkbox" name="supplies[]" value="black_drum" /> Black Drum<br />
<input type="checkbox" name="supplies[]" value="cyan_drum" /> Cyan Drum<br />
<input type="checkbox" name="supplies[]" value="magenta_drum" /> Magenta Drum<br />
<input type="checkbox" name="supplies[]" value="yellow_drum" /> Yellow Drum<br />
<input type="checkbox" name="supplies[]" value="waste_toner" /> Waste Toner<br />
<input type="checkbox" name="supplies[]" value="staples" /> Staples<br />
</div>
<td valign="top"> </td>
</tr>
这是我的php
}
$email_message = "Form details below.\n\n";
function clean_string($string) {
$bad = array("content-type","bcc:","to:","cc:","href");
return str_replace($bad,"",$string);
}
$email_message .= "First Name: ".clean_string($first_name)."\n";
$email_message .= "Last Name: ".clean_string($last_name)."\n";
$email_message .= "Company: ".clean_string($company)."\n";
$email_message .= "Location: ".clean_string($location)."\n";
$email_message .= "Machine Model: ".clean_string($machine_model)."\n";
$email_message .= "Supplies: ".clean_string($supplies)."\n";
$email_message .= "Email: ".clean_string($email)."\n";
$email_message .= "Telephone: ".clean_string($telephone)."\n";
$email_message .= "Comments: ".clean_string($comments)."\n";
// create email headers
$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
@mail($email_to, $email_subject, $email_message, $headers);
?>
就像我说的那样,我已经尝试了我认为的一切,但显然有些不对劲。我需要添加到我的php / html或更改以从我的复选框中获取所有响应而不是仅仅一个?如果有人有任何建议我会非常感激。 (请尽可能具体,就像我说的,我是新手)谢谢!
答案 0 :(得分:0)
$ supplies是一个数组,因为你将[]放到了它的表单中。你必须使用函数implode来分隔它们:
$supplies = implode(",", $supplies);
答案 1 :(得分:0)
$string = implode(", " $_POST['supplies']);
答案 2 :(得分:0)
您没有显示您分配$耗材的位置,但它是一个数组。分配时请尝试此操作。
$supplies = implode(',',$_POST['supplies']);
答案 3 :(得分:0)
1)这个HTML:
<input type="checkbox" name="tags[]" value="1" />
<input type="checkbox" name="tags[]" value="2" />
<input type="checkbox" name="tags[]" value="3" />
<input type="checkbox" name="tags[]" value="4" />
2)...成为这个PHP:
print_r($_POST['tags']);
// output
Array
(
[0] => 1
[1] => 2
[2] => 3
[3] => 4
)
3)在您的情况下,如果您只检查表格中的“黑色碳粉”和“青色鼓”,则应该在阵列中返回的唯一值是“black_toner”和“cyan_drum”。只需修改代码即可处理您获得的值。
4)我剪切/粘贴你的表单,并设置“action =”一个调用“phpinfo()”的脚本。以下是phpinfo的结果,仅检查black_toner和cyan_drum:
_POST["supplies"]
Array
(
[0] => black_toner
[1] => cyan_drum
)