On finalising the form I am finding that I cant quite make it work the way I had hoped that it would.
I have two fields, ifSelected a checkbox and definition a textbox. They are defined as:
Code: Select all
<input type="checkbox" name="isSelectedї]" id="isSelected" value="1">
<input type="text" name="definitionї]" id="definition" value="All Areas" size="80" maxlength="128">
The form displays lets say, three results with the checkbox value being 1, 2 and 3. I hit submit, accessing the data with the following code:
Code: Select all
foreach ($_POST['isSelected'] as $key=>$val) {
//just a test, if the echo is correct then you know how to get at the value
echo $_POST['definition'][$key].'<br />';
}
If I have clicked the first textbox, I get the right result. If I click say, the first and the third option however, it brings back the text in the first and the second text box. Alternately, if I click the second or third checkbox, it then brings back the text from the first text box.
Perhaps I should manually key the textboxes with the value of each checkbox so that the control arrays match. It just seems to me that the number of elements in the checkbox array depends on how many were checked, while the elements in the textbox array depend on how many iterations of it there were. Therefore the keys do not match between the two.
Am I way off base here? I'm thinking something along the lines of the following:
Code: Select all
<input type="checkbox" name="isSelectedї]" id="isSelected" value="345">
<input type="text" name="definitionї345]" id="definition" value="All Areas" size="80" maxlength="128">
Will this work? I'm kinda scared of breaking what is currently working now by altering it with an unknown.
Thanks.