It sure would be handy if I could 🙂
I've got a form that's got a bunch of checkboxes associated with each entry:Thank you all very much for your assistance!
<input type='text' name='name[]'>
<input type='text' name='value[]'>
<input type='checkbox' name='active[]'>
<input type='checkbox' name='visible[]'>
<input type='checkbox' name='available[]'>
<br>
<input type='text' name='name[]'>
<input type='text' name='value[]'>
<input type='checkbox' name='active[]'>
<input type='checkbox' name='visible[]'>
<input type='checkbox' name='available[]'>
<br>
<input type='text' name='name[]'>
<input type='text' name='value[]'>
<input type='checkbox' name='active[]'>
<input type='checkbox' name='visible[]'>
<input type='checkbox' name='available[]'>
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 on the page. I really need a single "on/off" solution instead of "either/or".
I have been trying to solve this for almost 5 hours now. I've tried javascript solutions, css and PHP and I can't figure it out. I can't use hidden form elements with the same name because the array is being built dynamically. If I place hidden element named 'active[]' with a value of 0 and then the checkbox with 'active[]' and a value of one, it just shows as two different array's values instead of the checkbox overwriting the hidden's entry.
Any thoughts on this? I've wasted a day on it in an effort not to have to rewrite all the HTML, jquery and js functions across all of my script but it's starting to get a bit ridiculous.