[英]form post multiple elements with multiple inputs with the same name
I have a form structure to save information about surveys and questions, this is kind of my code: 我有一个表单结构来保存有关调查和问题的信息,这是我的代码:
<form>
<div class=surveys>
Survey 1
<div class="questions">
Question 1
<input name="value_1">
<input name="value_2">
</div>
<div class="questions">
Question 2
<input name="value_1">
<input name="value_2">
</div>
...
</div>
<div class=surveys>
Survey 2
<div class="questions">
Question 1
<input name="value_1">
<input name="value_2">
</div>
<div class="questions">
Question 2
<input name="value_1">
<input name="value_2">
</div>
...
</div>
...
As you can see I have a form with many elements groups by divs called "Surveys", in which I have also many elements groups by divs as well called "Questions", the number of surveys and questions is defined by the number of elements I bring back from my DB. 如您所见,我有一个表格,其中包含许多按div划分的元素组,即“调查”,其中我也有许多按div划分的元素组,也称为“问题”,调查和问题的数量由我所定义的元素数来定义从我的数据库带回来。
This information is send to a controller (I'm using Laravel framework), and I would like to know what is the best way to send this data to the controller to manipulate it by the post request. 该信息被发送到控制器(我正在使用Laravel框架),并且我想知道什么是将数据发送到控制器以通过发布请求进行操作的最佳方法。 I'm a bit confused because the inputs name have to be the same in every element, or at least similar, but i don't know how to identify the input so I can match with the question.
我有点困惑,因为输入名称在每个元素中必须相同,或者至少相似,但是我不知道如何识别输入,因此我可以与问题匹配。
Hope you can help me, I would really appreciate. 希望你能帮助我,我会很感激。
Do this: 做这个:
name="survey[".$i."][."$j."]['value_1']"
Where i is index of survey and j is index of question. 其中i是调查指数,j是问题指数。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.