問題描述
表單提交為空 (Form submission empty)
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));
參考解法
方法 1:
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;
});
},
(by Tjorriemorrie、Tjorriemorrie)