I am not sure of the best-method approach (other than hacking for days) to try to get the values to retain in a series of checkboxes and dropdowns.
I have a checkbox group, the form element names are "languages[4]', 'languages[14]', 'languages[1]', etc.
Beside each checkbox in the HTML you will find a dropdown consisting of proficiencies. The names of each dropdown are 'proficiency[0]', 'proficiency[1]', etc. The dropdowns all contain the exact same data (pulled from a db query) as the checkboxes generated are all pulled from a db query.
The languages checkbox group will result in becoming an associative array in $_POST (the keys being the language ID from the db query); the proficiency array will become enumerative.
A check I have to do is this from the server end: If a corresponding language has been checked but no corresponding proficiency selected, or if a proficiency selected and no corresponding language checked, throw an error.
<?
$lookup->filterLanguages(); // OBTAIN LANGUAGE GROUP FOR CHECKBOX GROUP
$lookup->filterLanguageRankings(); // OBTAIN LANGUAGE RANKING FOR DROPDOWN
$languageIDArray = $lookup->getLanguageID();
$languageNameArray = $lookup->getLanguages();
$proficiencyArray = $lookup->getProficiencies();
$languageRankIDArray = $lookup->getLanguageRankID();
$languageRankArray = $lookup->getLanguageRankings();
for ($i = 0; $i < sizeof($languageIDArray); $i++) {
?>
<tr>
<td class="tabletext">
<input type=checkbox name="languages[<?= $i ?>]" value="<?= $languageIDArray[$i] ?>" <? preSelect($languages[$i], $languageIDArray[$i], 1) ?>> <?= $languageNameArray[$i] ?>
</td>
<td class="tabletext">
Proficiency:
<select name="proficiency[<?= $languageIDArray[$i] ?>]">
<option value=""> </option>
<? for ($j = 0; $j < sizeof($languageRankIDArray); $j++) { ?>
<option value="<?= $languageRankIDArray[$j] ?>" <? preSelect($proficiency[$languageIDArray[$i]], $languageIDArray[$j]) ?>>
<?= $languageRankArray[$j] ?>
</option>
<? } ?>
</select>
</td>
</tr>
<? } // END OF OUTER FOR LOOP FOR EACH LANGUAGE AND PROFICIENCY GROUP DISPLAY ?>
I am not clear at this point as to how to do this because of the fact that the languages and proficiencies do not line up upon returning to the page with the appropriate error (nor does any error message even appear in spite of the business-rule logic applying to the languages and proficiencies). I do not wish to "keep hacking" as I have been doing for days, what I would really like is some logic guidance from someone who has handled such a problem before, sort of a "I tackled this before and this is what I was thinking of doing.." type of approach.
Thanks
Phil