Php – HTML: Radio Button Array

arrays, forms, html, php, radio-button

Ok, so, I have a different kind of problem when dealing with Radio button arrays than the other threads.

I want to have it so that, depending on the answer selected, the value is saved on a different Array, yet I don't want to have the user being able to select more than one option from the same question.

Example:

Question 1<input type="radio" name="Array1[]" value="question1"/><input type="radio" name="Array2[]" value="question1"/><input type="radio" name="Array3[]" value="question1"/><input type="radio" name="Array4[]" value="question1"/>Question 2<input type="radio" name="Array1[]" value="question2"/><input type="radio" name="Array2[]" value="question2"/><input type="radio" name="Array3[]" value="question2"/><input type="radio" name="Array4[]" value="question2"/>

The purpose of this is so that I can arrange the questions themselves in one of 4 categories, and fill each array with the questions that got assigned to them.

Example:

Assuming 4 questions, and the answers being 1, 3, 1, 2, the resulting arrays I want would be:

Array1[0] = "question1"Array1[1] = "question3"Array2[0] = "question4"Array3[0] = "question3"Array4[] = Empty array

Can this be done or do I need a different approach to attain the desired output? I plan to process this form using PHP by the way.

EDIT: Some more details. An example usage.

<h1>What are your preferences?</h1><form type=...etc.>    <label>Cats</label>    <input type="radio" name="Love[]" value="Cats"/>    <input type="radio" name="Like[]" value="Cats"/>    <input type="radio" name="Dislike[]" value="Cats"/>    <input type="radio" name="Hate[]" value="Cats"/>    <label>Dogs</label>    <input type="radio" name="Love[]" value="Dogs"/>    <input type="radio" name="Like[]" value="Dogs"/>    <input type="radio" name="Dislike[]" value="Dogs"/>    <input type="radio" name="Hate[]" value="Dogs"/>    <label>Ferrets</label>    <input type="radio" name="Love[]" value="Ferrets"/>    <input type="radio" name="Like[]" value="Ferrets"/>    <input type="radio" name="Dislike[]" value="Ferrets"/>    <input type="radio" name="Hate[]" value="Ferrets"/>    <label>Turtles</label>    <input type="radio" name="Love[]" value="Turtles"/>    <input type="radio" name="Like[]" value="Turtle"/>    <input type="radio" name="Dislike[]" value="Turtles"/>    <input type="radio" name="Hate[]" value="Turtles"/><form>

Best Solution

You can only select one radio button per name, so if you have different names (as you do) users will be able to select more than one radio button per question. I'm sorry to say, but what you are proposing won't work. Instead you will have to maintain a manual list of numbers answered for the corresponding question. It seems like you know all the answers ahead of time, so this shouldn't be that big of a deal.