I've created 20 identical rows in a form using a loop, and then use a loop to process the arrays on the resulting page.
So, I've got the following fields and types:
Name: (text)
Title: (select)
Email: (text)
Seminar1: (checkbox)
Seminar2: (checkbox)
Lunch: (checkbox)
I'm having problems with the checkboxes. In the resulting page I may have only 8 items in the Seminar1 array, only 6 in the Seminar2 array, and only 7 in the Lunch array, though there may actually be 9 rows filled out with Names, Titles, etc. So what's happening is that the checkbox items are not lining up with the other items in the results. They are "stacking" so to speak.
So I thought I'd just make them radio buttons - that way every one would have some value and all the arrays would contain the same number of items.
The problem there is that when I loop through to create the rows of the form, all the radio buttons for Seminar1 are essentially the same - i.e. if you select Seminar1 "yes" for row 1, then you scroll down and select the same thing in row 8, row 1's "yes" becomes deselected.
Any ideas on how to fix this or work around it so I don't have to hard code 20 rows in both the form and resulting page?
Code for creating the rows in the form (using checkboxes):
<?php
$thecount = "1";
while ($thecount < 21) {
?>
<tr><td><input type = "text" name = "Name[]" size = "45" /></td>
<td><select name="Title[]">
<option value="" selected>Select Title</option>
<option value="Administrator">Administrator</option>
</select></td>
<td><input type = "text" name = "Email[]" size = "25" /></td></tr>
<TR>
<td colspan = "3"><p align = "center">
<input type = "checkbox" name = "Seminar1[]" value = "yes" /> <strong>Will attend Seminar 1</strong>
<input type = "checkbox" name = "Seminar2[]" value = "yes" /> <strong>Will attend Seminar 2</strong>
<input type = "checkbox" name = "Lunch[]" value = "yes" /> <strong>Will attend lunch</strong> </p></td></tr>
<?php
$thecount++;
}
?>
Resulting page - loop through arrays:
<?php
// set counter variable for loop
$x = 0;
// loop through records, error check and record
while ($x < 20) {
// get posted variables
$name = $POST['Name'][$x];
$title = $POST['Title'][$x];
$email = $POST['Email'][$x];
$seminar1 = $POST['Seminar1'][$x];
$seminar2 = $POST['Seminar2'][$x];
$lunch = $POST['Lunch'][$x];
// do something with them now
?>