I a using Angular $http to post an array to a php script. But the PHP script is only getting a single value from the array that I send with $http post from angular.
Angular form controller:
form.strategyData = {
mailData : {
strategies : ['test1','test2']
},
sent : false
}
form.processStrategy = function() {
$http({
method : 'POST',
url : '/sform',
data : $httpParamSerializer(form.strategyData.mailData),
headers : { 'Content-Type': 'application/x-www-form-urlencoded' }
})
.success(function(data) {
console.log('success')
});
};
PHP Script:
$strategies = $_POST['strategies'];
$message .= "Strategies: " . $strategies;
When I use console.log I do see the the 2 test values ['test1','test2'] inside the mailData
Inside PHP I only get the last value which is test2
When you call $httpParamSerializer(form.strategyData.mailData) your data send to server will be "strategies=test1&strategies=test2". That's reason inside PHP you get result is "test2".