Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Mubashar's avatar

How to get Checkedd Checkbox values From View to Controller only one check box. I am trying to create quiz page for user to take quiz.

Here is my View: four check boxes

 Option1< type="checkbox" class="example" name="">

 Option2< type="checkbox" class="example" value="false" name="Question1" >

 option3<type="checkbox" class="example" name="">

   option4<type="checkbox"  class="example" name="">
                  
                


                
                
                
                
                
                
0 likes
2 replies
Mubashar's avatar

And Here is my Testcontroller store method public function store(Request $request) { dd($request->input('Question1')); $test=new Test(); $test->Question1=$request->input('Question1'); $test->save(); flash('Test save successfully'); return redirect()->back(); }

bobbybouwmann's avatar
Level 88

You need to use a radio button instead. This way the browser can only submit one field and when the user clicks on another checkbox it will uncheck the current one.

<input type="radio" name="answer" value="a"> Answer A
<input type="radio" name="answer" value="b"> Answer B
<input type="radio" name="answer" value="c"> Answer C

You can then get the value like so

public function store(Request $request)
{
    $answer = $request->get('answer'); // a or b or c
}

Please or to participate in this conversation.