I have created a form that allows someone to create a quiz, all of the questions and the answers are stored in a database. You can see a simplified version of the form here:
http://jsfiddle.net/superuntitled/uaTtx/4/
Each question can have an infinite number of answers and only one answer can be correct. To denote the 'correct' answer, I am using radio buttons.
The problem that I am having is that only the selected radio button passes a value to my php code, see a sample $_POST
array of values (in this example, three answers for the question "What is a space station?"):
[text] => Array
(
[0] => A cosmic hotel
[1] => An interstellar depot
[2] => A closet organizer
)
[correct] => Array
(
[0] => 1
)
Even if the correct answer was "An interstellar depot", the first answer "A cosmic hotel" will be entered as the correct answer when I loop through this $_POST
array. This is because only a selected radio button will pass a value.
My radio input looks like this:
<input type="radio" name="answer[1][correct][]" value="1" />
The first set of brackets denotes the question it is associated with, and this number is incremented with each new question.
Does anyone have any ideas on how set the correct answer properly?