I have a dropdown form where you can select one or more items. The selected items I want to send to a backend php script that will insert the selected values into a database. This is my angular insert function:
insertRepair: function (id_telefon, id_culoare, arrayPiese) {
console.log(arrayPiese);
http.get('../php/insert_reparatii.php', {
params: {id_telefon: id_telefon, arrayPiese: arrayPiese,
id_culoare: id_culoare}
}).then(function () {
}
}
The call to this function is done like this:
serviceHttp.insertRepair($scope.phoneMP.selected.id, $scope.colorMP.selected.id, $scope.selectedPiesaMP.selected);
If I print into the console the arrayPiese array it will print for 2 selected items, something like this:
["Adezivi_Rama", "Polarizator"]
Now in the backend I retrieve the array list:
$arr = $_REQUEST['arrayPiese'];
If I print the $arr variable I get only one of two items printed. Need to mention that I migrated from jquery to angular, and from jquery I was able to send the entire array like this:
var arrayPiese = [];
$('.select2-selection__choice').each(function () {
arrayPiese.push($(this).attr('id'));
});
The url looks like this arrayPiese=Adezivi_Rama&arrayPiese=Polarizator&id_culoare=1&id_telefon=18
Do I need to serialize the array before sending it to php? Or what would be the best approach in sending an array to backend??