How to pass multiple checkbox values/id's to controller? Hello everyone!
Can somebody help me with advice? I have a table with multiple rows and I want to send selected checkbox values (post id's) to controller and then send emails to selected post id email addresses.
part of while loop:
echo '<td><input class="form-check-input" type="checkbox" value="'. $row['id'] .'" name="'. $row['id'] .'"flexCheckDefault"></td>';
Result of var_dump($_POST):
array(3) { ["_token"]=> string(40) "V8b70l32TFvPMopLJlG9tlntL7XFOcJoITaR7AXL" [1229]=> string(4) "1229" [1255]=> string(4) "1255" }
Thanks in advance!
@thesolarwin You can instead use the “square brackets” syntax for the names of your checkboxes:
<input class="form-check-input" type="checkbox" name="rows[]" value="{{ $row['id'] }}">
Now when you submit to your controller, you’ll have an array of values that you can iterate over:
$rows = $request->input('rows'); // an array of selected IDs
Also, try to use a template language like Blade instead of echo-ing a HTML string like that.
@martinbean Thank you very much. :) Good point about blade, this is just one part i haven't rewrited yet.
Please sign in or create an account to participate in this conversation.