I have a bunch of checkboxes in my laravel
-app, which I want to save as an array in my MySQL
database but I'm not sure how to do it.
So here are my input fields:
<input type="checkbox" class="form-check-input" name="vehicle[]" value="bmw">BMW
<input type="checkbox" class="form-check-input" name="vehicle[]" value="audi">Audi
<input type="checkbox" class="form-check-input" name="vehicle[]" value="mercedes">Mercedes
<input type="checkbox" class="form-check-input" name="vehicle[]" value="chrysler">Chrysler
<input type="checkbox" class="form-check-input" name="vehicle[]" value="chevrolet">Chevrolet
<input type="checkbox" class="form-check-input" name="vehicle[]" value="ford">Ford
For simple input fields I do this in my .js
file:
var formData = new FormData();
formData.append(
"name",
$("#uploadModal")
.find('input[name="name"]')
.val()
);
// etc. etc,
and then later on I submit the data by using axios
:
axios.post($("#uploadModal form").attr("action"), formData) ...
How can I add the checked checkbox
array to the formData?