would be grateful for some help on this:
I have a set of checkboxes where users are encouraged to select at least one option. I would like to store all of these options in a single variable using PHP and then in turn attach this variable on to the end of an email body to send to the site host using email. However, I can only seem to retrieve the last option that the user selects. I have tried using the array syntax (e.g. name="instrument[]") but I cannot seem to find a way to retrieve the values from this array. I have used the 'implode' method to store the post value but I keep on receiving an error message, saying "Warning: implode(): Invalid arguments passed in C:\xampp\htdocs\academy\contact-process.php on line 8".
My code is below:
Contact.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>
Contact-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>
At the moment this generates the error message as described above.
Anyone know a solution?
Thanks so much for any replies!!
Robert.