2014-03-27 50 views
0

我試圖處理與阿賈克斯
送到這裏的形式是我的ajax郵編:Symfony2的處理與阿賈克斯郵寄給jQuery的序列化形式

 $.post("{{ path('order_ad_banner') }}", 
     {form: $('#adOrderForm').serialize(), url: "{{ url }}"}, 
     function (data) { 
      $('#formWindow').html(data); 
     } 
    ); 

這裏我請求處理:

$receivedForm = $request->request->get('form', null); 
... 
$form = $this->createForm(new OrderType(), $order); 
if($receivedForm) { 
    $form->submit($receivedForm); 
} 

不幸的是這個綁定不起作用

回答

0

試試這個

$receivedForm = $request->request->get('adOrderForm', null); 
... 
$form = $this->createForm(new OrderType(), $order); 
if($receivedForm) { 
    $form->submit($receivedForm); 
} 
0

找到自己的解決方案:

$.post("{{ path('order_ad_banner') }}", 
     $('#adOrderForm').serialize() + "&" + $.param({url: "{{ url }}"}), 
     function (data) { 
      $('#formWindow').html(data); 
     } 
); 

$receivedForm = $request->request->get('adOrder', null); 
0

有一些更簡單的解決方案。

做這樣的事情:

$.ajax({ 
     type: "POST", 
     url: route, 
     data: $('#adOrderForm').serialize(), 
     success: function (data) 
     { 

     } 
}); 

而且在symfony的控制器:

public function someAction(Request $request) 
{ 
    ... 
    $form = $this->createForm(new OrderType(), $order); 
    $form->handleRequest($request); 
    if($form->isSubmitted() && $form->isValid()) 
    { 
     ... 
    } 
}