[英]Symfony I want to send form with many select with some name
I created form with many select generate with for 我创建了带有许多选择生成的表单
<form action="#" method="POST" id='from_quantity' name="from_quantity">
{% for PanierProduct in PanierProducts %}
<input type="hidden" name="idProduct" value="{{PanierProduct.id}}">
{% for i in 1..eReservation.ereservationmaxquantity %}
<option value="{{ i }}" {% if i == panier[PanierProduct.id] %} selected ="seleted" {% endif %}>{{ i }}
</option>
{% endfor %}
</form>
and in the jquery i use this code for send my form and it's work very good 在jquery中,我使用此代码发送表单,效果很好
$("#ConfirmQuantity").click(function(){
var url = Routing.generate('front_office', {baseDomaine : baseDomaineJS , _locale: 'en'});alert(data);
$.ajax({
type: "POST",
data: $("#from_quantity").serialize(),
url: url,
success: function (data) {
alert(data);
}
})
;
});
the problem new how can I receive this form in the controller I try many Proposal and no one work for exemple here i wan to get the all form but it doesn't work: 新的问题是如何在控制器中收到此表格,我尝试了很多建议,但这里没有人可以代表所有表格,但我想得到所有表格,但它不起作用:
$form = $request->request->get('from_quantity');
$responce = new JsonResponse();
return $responce->setData(array('res' => $form));
In controller put $this->getRequest()->request->all();
在控制器中放入
$this->getRequest()->request->all();
In there you have array with all POST variables. 那里有所有POST变量的数组。
You have mistake in generates your form. 您在生成表格时出错。 You should use array as element name.
您应该使用数组作为元素名称。
<form action="#" method="POST" id='from_quantity' name="from_quantity">
{% for PanierProduct in PanierProducts %}
<input type="hidden" name="idProduct[]" value="{{PanierProduct.id}}">
{% for i in 1..eReservation.ereservationmaxquantity %}
<option value="{{ i }}" {% if i == panier[PanierProduct.id] %}
selected="seleted" {% endif %}>{{ i }}
</option>
{% endfor %}
</form>
When want get all element: 要获取所有元素时:
$arr = $this->getRequest()->request->all(); foreach($arr as $row) {}
When want get first element: 要获取第一个元素时:
$element = $arr[0];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.