Reputation: 2000
i have a form that i increase the id of checkbox through a foreach with unknown size now when i submit i want to receive all of the sent data here is my code :
<form action="/somecontroller" method="post">
<div id="checkboxes" class="col-lg-2 text-center">
<input type="checkbox" name="rGroup" name="d{{$index}}" value="{{verta($pdates->date)->format('Y/m/d')}}" id="d{{$index}}"/>
<label class="whatever mt-3" for="d{{$index}}"> {{verta($pdates->date)->format('Y/m/d')}}
<hr>
{{$pdates->price}}</label>
</div>
</form>
and here is the controller :
$recived_data = $request->d{{$index}}; here i want to get all the checkboxes send by user
so how can i recive the data that user send which i dont know the number of checkboxes
Upvotes: 0
Views: 38
Reputation: 14268
You can use array syntax of the input element, and receive the array with selected items in the controller, so change your input checkbox to this:
<input type="checkbox" name="d[{{$index}}]" value="{{verta($pdates->date)->format('Y/m/d')}}" id="d{{$index}}"/>
Then in your controller:
$request->input('d'); // returns an array of indexes of all the selected checkboxes.
Upvotes: 1