smerny Posted December 19, 2010 Share Posted December 19, 2010 Why is it grouping the checked boxes instead of keeping them in order like area is? if(isset($_POST['submit'])){ for($i=0; $i<10; $i++){ echo "<br />Ignore = [".$_POST['ignore'][$i]."]"; if($_POST['ignore'][$i]!="true") echo ", Area = ".$_POST['area'][$i]; } } else { echo "<form method='post'><table>"; for($i=0; $i<10; $i++){ echo " <tr> <td><input type='checkbox' name='ignore[]' value='true' /></td> <td><input type='text' name='area[]' /></td> </tr>\n"; } echo " </table> <input type='submit' name='submit' value='Submit' /> </form>"; } Input: Checked - ignored Unchecked - a Checked - ignored2 Unchecked - b Checked - ignored3 Unchecked - c Unchecked - d Checked - ignored4 Unchecked - e Checked - ignored5 Output: Ignore = [true] Ignore = [true] Ignore = [true] Ignore = [true] Ignore = [true] Ignore = [], Area = c Ignore = [], Area = d Ignore = [], Area = ignored4 Ignore = [], Area = e Ignore = [], Area = ignored5 Quote Link to comment https://forums.phpfreaks.com/topic/222145-checkbox-array-in-form/ Share on other sites More sharing options...
PFMaBiSmAd Posted December 19, 2010 Share Posted December 19, 2010 I recommend you add the following to your code so that you can see what you are actually getting- echo '<pre>',print_r($_POST,true),'</pre>'; You only get the checkboxes that are checked, but you get all the text fields. If you want to assoicate the correct checkbox with the same numbered text field you would need to put the $i index counter into the [] array brackets so that ignore[0] corresponds to area[0], ignore[1] corresponds to area[1], ... Quote Link to comment https://forums.phpfreaks.com/topic/222145-checkbox-array-in-form/#findComment-1149300 Share on other sites More sharing options...
smerny Posted December 19, 2010 Author Share Posted December 19, 2010 thanks for the answer and the advice Quote Link to comment https://forums.phpfreaks.com/topic/222145-checkbox-array-in-form/#findComment-1149304 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.