Monday, 30 January 2017

angularjs - PHP $_POST Not Returning Values

In PHP I have a form that submits data to a PHP script. The PHP script prints the values, using:



  $raw_post = file_get_contents('php://input');
print_r($raw_post);
print_r($_POST);
print_r($_REQUEST);


All of these come back empty/null arrays EXCEPT $raw_post (aka, php://input).




Chrome's Developer Tools also show that the values have been submitted through the payload as a POST request and it is a status of 200 OK, yet PHP does not set them to the $_POST array at all.



Results in the $raw_post:



{"company_name":"test","primary_contact":"test","address":"test","function":"test","phone":"test","fax":"test","url":"test"}


Results in $_POST:




Array
(
)


Results in $_REQUEST:



Array
(
)



I am unable to find a solution to this issue ... could anybody help here?



The form is submitted from AngularJS to a PHP script.



New code (url-encoded):



app.factory('Companies', function($resource) {
return $resource('/api.php/companies/:id', {id:''}, {

'query': {method: 'GET', isArray: true},
'view': {method: 'GET', isArray: true},
'save': {
method: 'POST',
isArray: true,
headers: {'Content-Type': 'application/x-www-form-urlencoded'}},
});
});

No comments:

Post a Comment

c++ - Does curly brackets matter for empty constructor?

Those brackets declare an empty, inline constructor. In that case, with them, the constructor does exist, it merely does nothing more than t...