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 emai
Here's my solution:
With an array of checkboxes in the html like so...
I then fix the posted array with this function...
$_POST[ 'something' ] = $this->fixArrayOfCheckboxes( $_POST[ 'something' ] );
function fixArrayOfCheckboxes( $checks ) {
$newChecks = array();
for( $i = 0; $i < count( $checks ); $i++ ) {
if( $checks[ $i ] == 'off' && $checks[ $i + 1 ] == 'on' ) {
$newChecks[] = 'on';
$i++;
}
else {
$newChecks[] = 'off';
}
}
return $newChecks;
}
This will give me an array with values of either 'on' or 'off' for each (and every) checkbox.
Note that the hidden input MUST be BEFORE the checkbox input in order for the function to work right.