Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I place checkbox values in the message using POST?
    primarykey
    data
    text
    <p>I have been working on creating a PHP email form recently and cannot manage to send the checkbox values correctly. The form is one I found elsewhere and have been modifying. The HTML is fairly straightforward.</p> <pre><code>&lt;label for="needs"&gt;I am looking for...&lt;/label&gt; &lt;input name="needs[]" id="needs" type="checkbox" value="product list"&gt;A Product List&lt;br&gt; &lt;input name="needs[]" id="needs" type="checkbox" value="educational support"&gt;Educational Support&lt;br&gt; &lt;input name="needs[]" id="needs" type="checkbox" value="catering options"&gt;Catering Options&lt;br&gt; &lt;input name="needs[]" id="needs" type="checkbox" value="party ideas"&gt;Party Ideas&lt;br&gt; &lt;input name="needs[]" id="needs" type="checkbox" value="healthy alternatives"&gt;Healthy Alternatives&lt;br&gt; &lt;input name="needs[]" id="needs" type="checkbox" value="other"&gt;Other (please specify)&lt;br&gt; </code></pre> <p>As of right now, when I send it through the PHP it simply returns either a single selected value or if multiple are selected is says "array". What I would like is for the message of the mail being sent to me to list the selected values. I have searched elsewhere, but have not found a situation the same as mine yet. Here is the PHP:</p> <pre><code>&lt;?php $msg= 'Name: '.$_POST['name'].'&lt;br /&gt; Category: '.$_POST['category'].'&lt;br /&gt; Email: '.$_POST['email'].'&lt;br /&gt; Phone: '.$_POST['telephone'].'&lt;br /&gt; Looking for: '.$_POST['needs'].'&lt;br /&gt; IP: '.$_SERVER['REMOTE_ADDR'].'&lt;br /&gt;&lt;br /&gt; Message:&lt;br /&gt;&lt;br /&gt; '.nl2br($_POST['message']).' '; ?&gt; </code></pre> <p>The rest of the code is setup and sending of the message. I realize that there are other ways of doing what I want, but would like to continue using the $msg that is included here.</p> <p>Any help would be greatly appreciated, thanks.</p> <p>Modified code:</p> <pre><code>$msg= 'Name: '.$_POST['name'].'&lt;br /&gt; Category: '.$_POST['category'].'&lt;br /&gt; Email: '.$_POST['email'].'&lt;br /&gt; Phone: '.$_POST['telephone'].'&lt;br /&gt; Looking for: '.(is_array($_POST['needs'])?implode("\n", $_POST['needs']):$_POST['needs']).'&lt;br /&gt; IP: '.$_SERVER['REMOTE_ADDR'].'&lt;br /&gt;&lt;br /&gt; Message:&lt;br /&gt;&lt;br /&gt; '.nl2br($_POST['message']).' '; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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