将不胜感激这方面的一些帮助:
我有一组复选框,鼓励用户选择至少一个选项。我想使用 PHP 将所有这些选项存储在一个变量中,然后将此变量附加到电子邮件正文的末尾,以使用电子邮件发送到站点主机。但是,我似乎只能检索用户选择的最后一个选项。我曾尝试使用数组语法(例如 name="instrument[]"),但似乎找不到从该数组中检索值的方法。我使用了 'implode' 方法来存储 post 值,但我一直收到一条错误消息,上面写着“警告:implode(): Invalid arguments pass in C:\xampp\htdocs\academy\contact-process.php 在线8"。
我的代码如下:
联系方式.html
<tr>
<td>
<label id="checkbox">Piano</label>
<input id="piano" type="checkbox" name="instrument[]" value="Piano" class="required" title="Please check at least one option.">
</td>
<td>
<label id="checkbox">Flute</label>
<input id="flute" type="checkbox" name="instrument[]" value="Flute">
</td>
<td>
<label id="checkbox">Singing</label>
<input id="singing" type="checkbox" name="instrument[]" value="Singing">
</td>
</tr>
<tr>
<td>
<label id="checkbox">Violin</label>
<input id="violin" type="checkbox" name="instrument[]" value="Violin">
</td>
联系-process.php:
<pre><?php
$title = $_POST["title"];
$forname = $_POST["firstname"];
$surname = $_POST["lastname"];
$phone = $_POST["phone"];
$instrument = implode(' ', $_POST["instrument"]);
$hear = $_POST["method"];
$enrole = $_POST["child"];
$dob = $_POST["date"];
$message = $_POST["enquiry"];
$email_body = "";
$email_body = $email_body . "Title: " . $title . "\n";
$email_body = $email_body . "Forname: " . $forname . "\n";
$email_body = $email_body . "Surname: " . $surname . "\n";
$email_body = $email_body . "Telephone Number: " . $phone . "\n";
$email_body = $email_body . "Heard About You From: " . $hear . "\n";
$email_body = $email_body . "Interested In Learning: " . $instrument . "\n";
$email_body = $email_body . "Would Like To Enrole A(n): " . $enrole . "\n";
$email_body = $email_body . "Child's Date of Birth: " . $dob . "\n";
$email_body = $email_body . "Message: " . $message;
echo $email_body;
?></pre>
目前,这会生成如上所述的错误消息。
有人知道解决方案吗?
非常感谢您的回复!!
罗伯特。