我正在生成一些表单,我将这些表单分组为四个表单字段组,如http://options-html5.herokuapp.com/ --> see other information tab
这是我生成表单
的jquery代码//Add Partner
$('.partner_create_button').on('click',function(){
$('<article class="crud_item">
<span class="delete_partner">Delete Partner</span><br/>
<label class="name_label">Partner Name</label>
<input class="text_element" type="text" name="partner_crud[]" placeholder="partner name" />
<label class="name_label">Partner URL</label>
<input class="text_element" type="text" name="partner_crud[]" placeholder="partner url"/>
<label class="name_label">Partner Logo</label>
<input class="text_element"type="text" name="partner_crud[]" placeholder="partner logo" />
<span class="get_image_from_the_media_centre">Get Image From Media Centre</span>
<label class="name_label">Partner Status</label>
<select class="text_element" name="partner_crud[]">
<option value="partner status" selected>Select your option</option>
<option>Published</option>
<option>Pending Approval</option>
<option>In Future</option>
</select>
</article>').appendTo('.partners_holder');
然而,当我提交表格并处理$_POST
时,我得到了这个
[partner_crud] => Array
(
[0] => partner name
[1] => partner url
[2] => partner logo
[3] => partner status
[4] => partner name
[5] => partner url
[6] => partner logo
[7] => partner status
[8] => partner name
[9] => partner url
[10] => partner logo
[11] => partner status
[12] => partner name
[13] => partner url
[14] => partner logo
[15] => partner status
[16] => partner name
[17] => partner url
[18] => partner logo
[19] => partner status
)
已发布的字段都在一个数组中。是否有一种方法可以修复我的表单以获取发布值的格式?
[0] => Array
(
[0] => partner name
[1] => partner url
[2] => partner logo
[3] => partner status
)
[1] => Array
(
[0] => partner name
[1] => partner url
[2] => partner logo
[3] => partner status
)
[2] => Array
(
[0] => partner name
[1] => partner url
[2] => partner logo
[3] => partner status
)
在上面,每个表单都有自己的数组。
答案 0 :(得分:0)
答案 1 :(得分:0)
您所要做的就是通过将名称更改为:
将每组输入放在单独的数组中name="partner_crud[$i][]"
每次通过jquery $ i添加新输入时,都应该增加,所以你应该跟踪当前的数量。