When you use input with type radio only selected value is sent to the server. If you want to send multiple then you need checkbox.
Dec 14, 2020
7
Level 4
form validation: grouped radio buttons
Hi,
I have a form with several groups of radio buttons. I have left some HTML out to make it easier to read but the main HMTL is down here
<input type="radio" name="subjects[math]" id="subjects[math]['I like it']" value="I like it">
<input type="radio" name="subjects[math]" id="subjects[math]['I dont mind it']" value="I dont mind it">
<input type="radio" name="subjects[math]" id="subjects[math]['not for me']" value="not for me">
<input type="radio" name="subjects[math]" id="subjects[math]['Not applicable']" value="Not applicable">
<input type="radio" name="subjects[english]" id="subjects[english]['I like it']" value="I like it">
<input type="radio" name="subjects[english]" id="subjects[english]['I dont mind it']" value="I dont mind it">
<input type="radio" name="subjects[english]" id="subjects[english]['not for me']" value="not for me">
<input type="radio" name="subjects[english]" id="subjects[english]['Not applicable']" value="Not applicable">
<input type="radio" name="subjects[music]" id="subjects[music]['I like it']" value="I like it">
<input type="radio" name="subjects[music]" id="subjects[music]['I dont mind it']" value="I dont mind it">
<input type="radio" name="subjects[music]" id="subjects[music]['not for me']" value="not for me">
<input type="radio" name="subjects[music]" id="subjects[music]['Not applicable']" value="Not applicable">
My validation is not working
public function rules()
{
return [
'submit' => 'required',
'subjects.*' => 'required',
];
}
If I select a couple of values, the validation passes and I get
array:2 [▼
"submit" => "Next"
"subjects" => array:2 [▼
"math" => "I like it"
"english" => "I like it"
]
]
Why is the rest of the checkboxes not validated? I tried several other solutions including one where I replaced the subject(math, english,...) with a number but that's not working either.
What am I missing?
Please or to participate in this conversation.