Thank you all very much for your assistance!
To explain better, here’s a demo form of what I want to do:
<input type='text' name='name[]'>
<input type='text' name='value[]'>
<input type='checkbox' name='active[]'>
<br>
<input type='text' name='name[]'>
<input type='text' name='value[]'>
<input type='checkbox' name='active[]'>
<br>
<input type='text' name='name[]'>
<input type='text' name='value[]'>
<input type='checkbox' name='active[]'>
and on the PHP side, it builds an array, binding the elements together for me which I can loop through on the processing side.
$i = 0;
WHILE(ISSET($_POST['name'][$i])){
$name = $_POST['name'][$i];
// Do important stuff
$i = ++$i;
}
but with checkboxes, if it’s not checked, it doesn’t exist in the array, so if I check the first row’s box and third row’s box, I will get a checked box on the first and second row, since PHP doesn’t know that the unchecked box deserved a spot in the array.
This could be easily resolved with radio buttons, since it sends a value, regardless of which you use:
<input type='text' name='name[]'>
<input type='text' name='value[]'>
<input type='radio' name='active[]' value='1'>
<input type='radio' name='active[]' value='0'>
<br>
<input type='text' name='name[]'>
<input type='text' name='value[]'>
<input type='radio' name='active[]' value='1'>
<input type='radio' name='active[]' value='0'>
<br>
<input type='text' name='name[]'>
<input type='text' name='value[]'>
<input type='radio' name='active[]' value='1'>
<input type='radio' name='active[]' value='0'>
but I don’t have room to fit the radio buttons(My actual rows utilize three checkboxes, so the differing real estate used by the two is sizeable)
In my code, I deal with this array 6 times on three different pages, both with PHP and with jquery, allowing me to reorder, add to and delete rows. It’s got a lot of use in my script. I could either rewrite all of the PHP and javascript across all the pages to not work with the genius of a PHP array…
Or I could make a radio button look like a checkbox.
This is why I’m trying to do this. Above, I posted the codepen of a visual representation of something that could work but I don’t know how to turn that div into a form element that will give me a 0 or 1, depending on it’s setting.
Just let me know if I’ve still managed to miss the important bits