Chud37 Posted October 17, 2011 Share Posted October 17, 2011 Hello, I have to write a booking form and in my form I have a jQuery function that allows to add as many extra people as you like. For each person, they have to select which days they want to be there for, IE, friday, saturday, sunday or monday. The checkboxes are as such: <input type="checkbox" id="a_friday" name="adultFri[]" class="hideMe"> <input type="checkbox" id="a_friday" name="adultSat[]" class="hideMe"> <input type="checkbox" id="a_friday" name="adultSun[]" class="hideMe"> <input type="checkbox" id="a_friday" name="adultMon[]" class="hideMe"> Which is fine. However, because some of the checkboxes will not be selected, the arrays dont line up when I recieve them. For example, if adult #1 checks friday and saturday, and adult #2 checks sunday and monday, I end up with this: adultFri[0] = on adultSat[0] = on adultSun[0] = on adultMon[0] = on The adultSun and adultMon should both be at point 1. This is because If the checkbox isnt checked, it doesnt get passed through. Does anyone have a solution to this? Please help! Thanks. Quote Link to comment Share on other sites More sharing options...
ManiacDan Posted October 17, 2011 Share Posted October 17, 2011 Then name the input boxes adultFri[1] and adultFri[2] for adults 1 and 2. Then you'll have to: foreach ( $_POST['adultFri'] as $adultId => $value ) You could also name them: adult[Fri][1] ...and do a nested loop. -Dan Quote Link to comment Share on other sites More sharing options...
Chud37 Posted October 18, 2011 Author Share Posted October 18, 2011 Thanks, I didnt of 2d arrays. It took a bit of fiddling but got there in the end! Cheers! Quote Link to comment 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.