Reputation: 2590
I have the following radio buttons
<input type="radio" class='form-control' name="progress_type[]" value="Journal Papers"><span class='radio-label'>Journal Paper</span>
<input type="radio" class='form-control' name="progress_type[]" value="Conference Proceeding"><span class='radio-label'>Conference Proceeding</span>
<input type="radio" class='form-control' name="progress_type[]" value="Conference Presentation"><span class='radio-label'>Conference Presentation</span>
I want to add another block of radio group, with the same name value so that in PHP I can get an array of selected values.
I am adding the next radio button group with the following jQuery code
$(this).parent().prepend('<p class="help-block">Type</p><input type="radio" class="form-control" name="progress_type[]" value="Journal Papers"><span class="radio-label">Journal Paper</span><input type="radio" class="form-control" name="progress_type[]" value="Conference Proceeding"><span class="radio-label">Conference Proceeding</span><input type="radio" class="form-control" name="progress_type[]" value="Conference Presentation"><span class="radio-label">Conference Presentation</span><p class="help-block">Details</p><input type="text" class="form-control input-margin" name="progress_pub[]">');
It adds but when I test, I can only select 1 radio button out of 6. Although I thought I can choose 2 different values from the two different radio button groups.
Please note that I dont know how many radio button groups users will create.
Should I use two dimensional arrays?
Any help?
Thanks
Upvotes: 1
Views: 172
Reputation: 781004
Instead of using progress_type[]
as the names for your radio buttons, use progress_type[id]
, where you replace id
with the index of that section of the form.
Then when you're processing the parameters, you can use $_POST['progress_type'][$id]
to get that block's selection.
Upvotes: 1
Reputation: 6908
Use a different name
property for your different groups. So progress_type[]
will be the name of your first group, and perhaps progress_type_2[]
will be the name of your second. If this was part of a form, it's the name
property that you will use to access the different answers. (That being said, you probably don't want to add the array brackets to the ends of your names -- it is enought to call them progress_type
and progress_type_2
).
Upvotes: 1