Note that there are some explanatory texts on larger screens.

plurals
  1. PORetrieving multiple checkbox values with PHP
    text
    copied!<p>would be grateful for some help on this:</p> <p>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".</p> <p>My code is below:</p> <p>Contact.html</p> <pre><code>&lt;tr&gt; &lt;td&gt; &lt;label id="checkbox"&gt;Piano&lt;/label&gt; &lt;input id="piano" type="checkbox" name="instrument[]" value="Piano" class="required" title="Please check at least one option."&gt; &lt;/td&gt; &lt;td&gt; &lt;label id="checkbox"&gt;Flute&lt;/label&gt; &lt;input id="flute" type="checkbox" name="instrument[]" value="Flute"&gt; &lt;/td&gt; &lt;td&gt; &lt;label id="checkbox"&gt;Singing&lt;/label&gt; &lt;input id="singing" type="checkbox" name="instrument[]" value="Singing"&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt; &lt;label id="checkbox"&gt;Violin&lt;/label&gt; &lt;input id="violin" type="checkbox" name="instrument[]" value="Violin"&gt; &lt;/td&gt; </code></pre> <p>Contact-process.php:</p> <pre><code>&lt;pre&gt;&lt;?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; ?&gt;&lt;/pre&gt; </code></pre> <p>At the moment this generates the error message as described above.</p> <p>Anyone know a solution?</p> <p>Thanks so much for any replies!!</p> <p>Robert.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload