Reputation: 17282
Submitting this:
But my entity and $form->getData()
is empty (all the fields are null).
Controller:
/**
* @Route("/persons", requirements={"_format" = "json"}, name="sales_persons_create")
* @Method({"POST"})
*/
public function createAction()
{
$salesPerson = new SalesPerson();
$form = $this->createForm(new SalesPersonType(), $salesPerson);
$form->handleRequest($this->getRequest());
die(var_dump($salesPerson));
Upvotes: 1
Views: 1864
Reputation: 17282
As I'm not sending the rendered form of Symfony2, the values are not matched as @Cerad stated.
However, Symfony still couldn't pick up the post values. The following example below allowed me to receive the post values (although I'm not sure of the workings):
$scope.saveLead = function() {
var formData = new FormData();
formData.append('date', $scope.leadNew.date);
formData.append('sales_person', $scope.leadNew.sales_person.id);
formData.append('file', $scope.leadNew.file);
leadsServ.create(formData).then(function(data) {
...
and a service example
create: function(formData) {
return $http.post(URL_SITE + '/categories', formData, {
headers: {'Content-Type': undefined },
transformRequest: angular.identity
}).then(function(result) {
//console.info('leadsServ create', result.data);
return result.data;
});
},
Upvotes: 1