【问题标题】:Form submission empty表单提交为空
【发布时间】:2013-08-16 10:44:05
【问题描述】:

提交:

但我的实体和$form->getData() 为空(所有字段均为空)。

控制器:

/**
 * @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));

【问题讨论】:

  • 从浏览器查看表单的 html。您会看到输入元素名称比“电子邮件”更复杂。 S2 添加了更多信息以支持多种形式等。调整您的 js 以发布实际的元素名称。

标签: forms symfony post


【解决方案1】:

由于我没有发送 Symfony2 的渲染形式,因此值与 @Cerad 所述不匹配。

但是,Symfony 仍然无法获取帖子值。下面的示例允许我接收帖子值(尽管我不确定其工作原理):

$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) {
...

和一个服务示例

     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;
            });
        },

【讨论】:

  • 我也有同样的问题。你解决了吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2016-12-19
  • 2014-12-24
  • 2022-01-26
  • 2013-01-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多