I have added a checkbox to a form that the user can dynamically add rows to. You can see the form here.
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:
<input type="checkbox" name="mailing[]" value="Yes">
Then in the PHP I have this:
$mailing = trim(stripslashes($_POST['mailing'][$i]));
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.
One further issue is that I would like the value 'No' to be generated for unchecked checkboxes.
Could someone help with this?
Thanks,
Nick
Form:
<form method="post" action="bookingenginetest.php">
<p>
<input type="checkbox" name="mailing[]" value="Yes">
<label>Full Name:</label> <input type="text" name="name[]">
<label>Email:</label> <input type="text" name="email[]">
<label>Telephone:</label> <input type="text" name="telephone[]">
<span class="remove">Remove</span>
</p>
<p>
<span class="add">Add person</span><br /><br /><input type="submit" name="submit" id="submit" value="Submit" class="submit-button" />
</p>
</form>
Cloning script:
$(document).ready(function() {
$(".add").click(function() {
var x = $("form > p:first-child").clone(true).insertBefore("form > p:last-child");
x.find('input').each(function() { this.value = ''; });
return false;
});
$(".remove").click(function() {
$(this).parent().remove();
});
});
<input type="checkbox" name="mailing[]" value="" checked />
– gne00 Jun 16 '11 at 18:18