mardi 16 février 2021

Adding values of radio buttons to array

I'm trying to make student skip form and adding values to array, but there is "Undefined offset: 3" error. Here is the controller:

    public function skip(Request $request, $data = array())
    {
        $students = Student::where('group_id', 1)->get();
        $result=[];

        if ($request->has('submit')) {
            foreach($students as $student) {
               array_push($result, $data[$student->id]);
            }}
        return view ('skip', compact('students', 'result'));
    }
}

and view:

                        <form method="POST" action="">
                            @csrf
                            @foreach($students as $student)

                                <div class="radiobtns-group">

                                    <div class="btn-group btn-group-toggle" data-toggle="buttons">

                                        

                                        <label class="btn btn-success">

                                            <input type="radio" name="" value="1" autocomplete="off" checked>Yes
                                        </label>
                                        <label class="btn btn-danger">

                                            <input type="radio" name="" value="0" autocomplete="off">No
                                        </label>

                                    </div>
                                </div>
                        @endforeach
                    </div>




                    <button name='submit' type="submit" class="btn btn-primary">
                        Add
                    </button>

                    </form>
                    

                

i know, it needs to be done in js, but i don't know it yet. Maybe you can help or guide in other ways to solve it, thnx.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire