Not sure if the question title is clear enough - but what I was referring to is - is it a bad practice to give a numeric value say 102 to the name attribute of a radio button like
<input type="radio" name="102" value="2032" /> Hello World
If it is a bad idea - the how do I handle this situation. I have a multiple choice exam where all 60 questions are displayed on the page at once.
The questions are stored in a question array and for each question - the multiple choices are stored in an answer array
This is the for loop which generates the 60 questions with their multiple choice answers - right now I'm using question_id as the value for radio buttons
<?php
$question_ids = array_keys($this->question_array);
foreach($question_ids as $question_id)
{
$question = $this->question_array[$question_id];
$answers = $this->answer_array[$question_id];
?>
<div>
<strong>Q) <?php echo $question['question'];?></strong>
<div>
<?php foreach ($answers as $answer) { ?><br/>
<input type="radio" name="<?php echo $question_id;?>" value="<?php echo $answer['answer_id'];?>" /> <?php echo $answer['answer'];?>
<?php } ?>
</div>
</div>
<?php
} ?>
So I have assigned name with question_id and value with answer_id - so on server side - I will know for which question which answer option was selected - needless to say they are unique autogenerated id's from the database
foreach ($_POST as $key => $value)
echo "For question id ".htmlspecialchars($key)." answer selected is ".htmlspecialchars($value)."<br>";
If assigning number is a bad idea - why is that. The other option for me is to assign a name value like name="questionId-102" and on the server side parse it.
Let me know what is the best way to handle this. Thanks