I have this form with 10 dropdown selections to choose from and a final checkbox disclaimer at the bottom.
So for example if the user selected all 10 answers and forgets to check the disclaimer box at the bottom and clicks submit, the form will come back with an error message that they didn’t agree to the disclaimer but all the answers they had previously selected are gone and they would have to re-do that. I am trying to find a best practice way to handle this without repeating so much code…
What I have it works but it is crazy redundant especially if I will have 100 questions.
<select name="question1" id="question1">
<?php if ($question[0] == '0') {
$first = 'selected="selected"';
$second = '';
$third = '';
$fourth = '';
} elseif ($question[0] == '1') {
$first = '';
$second = 'selected="selected"';
$third = '';
$fourth = '';
} elseif ($question[0] == '2') {
$first = '';
$second = '';
$third = 'selected="selected"';
$forth = '';
} elseif ($question[0] == '3') {
$first = '';
$second = '';
$third = '';
$forth = 'selected="selected"';
}
?>
<option value="0" <?php echo $first; ?>>Answer 1</option>
<option value="1" <?php echo $second; ?>>Answer 2</option>
<option value="2" <?php echo $third; ?>>Answer 3</option>
<option value="3" <?php echo $fourth; ?>>Answer 4</option>
</select>
This is only for 1 question so you can imagine I would have to repeat that for all questions. There must be a better way to do this?
Thanks…
Is usually how it’s done.