Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to pass an array of checked/unchecked checkbox values to PHP email generator?
    text
    copied!<p>I have added a checkbox to a form that the user can dynamically add rows to. You can see the form <a href="http://www.bodhitreebrighton.org.uk/bookingtest.html" rel="nofollow">here</a>.</p> <p>I use an array to pass the values for each row to a PHP email generator, and all works fine for other inputs, but I can't get the checkbox to work. The checkbox input currently looks like this:</p> <pre><code>&lt;input type="checkbox" name="mailing[]" value="Yes"&gt; </code></pre> <p>Then in the PHP I have this:</p> <pre><code>$mailing = trim(stripslashes($_POST['mailing'][$i])); </code></pre> <p>But it is not working as expected, i.e. I am only seeing 'Yes' for the first checkbox checked, and nothing for subsequent checkboxes that are checked.</p> <p>One further issue is that I would like the value 'No' to be generated for unchecked checkboxes.</p> <p>Could someone help with this?</p> <p>Thanks,</p> <p>Nick</p> <p><strong>Form:</strong></p> <pre><code>&lt;form method="post" action="bookingenginetest.php"&gt; &lt;p&gt; &lt;input type="checkbox" name="mailing[]" value="Yes"&gt; &lt;label&gt;Full Name:&lt;/label&gt; &lt;input type="text" name="name[]"&gt; &lt;label&gt;Email:&lt;/label&gt; &lt;input type="text" name="email[]"&gt; &lt;label&gt;Telephone:&lt;/label&gt; &lt;input type="text" name="telephone[]"&gt; &lt;span class="remove"&gt;Remove&lt;/span&gt; &lt;/p&gt; &lt;p&gt; &lt;span class="add"&gt;Add person&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;input type="submit" name="submit" id="submit" value="Submit" class="submit-button" /&gt; &lt;/p&gt; &lt;/form&gt; </code></pre> <p><strong>Cloning script:</strong></p> <pre><code>$(document).ready(function() { $(".add").click(function() { var x = $("form &gt; p:first-child").clone(true).insertBefore("form &gt; p:last-child"); x.find('input').each(function() { this.value = ''; }); return false; }); $(".remove").click(function() { $(this).parent().remove(); }); }); </code></pre>
 

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