首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >用php实现HTML表单的分组关联数组

用php实现HTML表单的分组关联数组
EN

Stack Overflow用户
提问于 2014-01-03 14:43:21
回答 1查看 165关注 0票数 0

我在基于表格的网页表单上工作。每一行都有单独的基准。在填写完表单的所有字段后,它应该在php中分组为一个关联数组。但经过多次试验,我并没有得到确切的结果。

生成的表单

代码语言:javascript
运行
复制
            <table width="60%" class="table table-striped table-bordered table-hover att  doodleTable">
                <thead>
                    <tr>
                        <th width="2%">ID</th>
                        <th width="10%"> Emp ID / Name </th>
            <!--                                        <th width="10%"></th>-->
                        <th width="3%">Site</th>
                        <th width="5%"> Attendance </th>
                        <th width="3%">Salary/hr</th>
                        <th width="5%">In time</th>
                        <th width="5%">Out time</th>
                        <th width="3%">Lunch Time</th>
                        <th width="3%">Over Time</th>
                        <th width="3%">Advance Amt</th>
                        <th width="3%">Total time</th>
                    </tr>
                </thead>
                <form method="POST" action="http://example.com/attendance/update" accept-charset="UTF-8"><input name="_token" type="hidden" value="ZZVYZejVpAkVfjeTcs58q8JXwrcptOsinTNr6Xha">                                    <tbody>
                        <tr>
                            <th width="2%">2</th>
                            <th width="10%"> SEO067 / Nagaraj </th>
                    <input  style="display:none" type="text" name="att[emp_id]" value='SEO067'  hidden="">
                    <th  width="5%" style="display:none"><input type="text" name="att[dt]" class="form-control date-pic-choose" readonly="" hidden=""> </th>
                    <th width="5%" style="display:none"><input type="text" name="att[site]" class="form-control date-pic-choose" readonly="" hidden=""> </th>
                    <th width="7%"> <input type="text" name="att[SEO067][][site]" class="form-control site"> </th>
                    <th width="3%"> 
                        <input type="radio" name="att[SEO067][st]" value="p" id="attendance_0">P   
                        <input type="radio" name="att[SEO067][st]" value="a" id="attendance_0">A
                    </th>
                    <th width="7%"> <input type="text" name="att[SEO067][sh]" class="form-control sal"> </th>
                    <th width="3%"> <input type="text" name="att[SEO067][wt]" class="form-control intime">  </th>
                    <th width="3%"> <input type="text" name="att[SEO067][ot]" class="form-control outtime">  </th>
                    <th width="3%"> <input type="text" name="att[SEO067][lt]" class="form-control lt"> </th>
                    <th width="3%"> <input type="text" name="att[SEO067][ovrtime]" class="form-control ovrtime">  </th>
                    <th width="3%"> <input type="text" name="att[SEO067][aa]" class="form-control">  </th>
                    <th width="3%"> <input type="text" name="att[SEO067][twt]" class="form-control twt">  </th>
                    </tr>
                    <tr>
                        <th width="2%">3</th>
                        <th width="10%"> SEO067rrr / Nagaraj </th>
                    <input  style="display:none" type="text" name="att[emp_id]" value='SEO067rrr'  hidden="">
                    <th  width="5%" style="display:none"><input type="text" name="att[dt]" class="form-control date-pic-choose" readonly="" hidden=""> </th>
                    <th width="5%" style="display:none"><input type="text" name="att[site]" class="form-control date-pic-choose" readonly="" hidden=""> </th>
                    <th width="7%"> <input type="text" name="att[SEO067rrr][][site]" class="form-control site"> </th>
                    <th width="3%"> 
                        <input type="radio" name="att[SEO067rrr][st]" value="p" id="attendance_0">P   
                        <input type="radio" name="att[SEO067rrr][st]" value="a" id="attendance_0">A
                    </th>
                    <th width="7%"> <input type="text" name="att[SEO067rrr][sh]" class="form-control sal"> </th>
                    <th width="3%"> <input type="text" name="att[SEO067rrr][wt]" class="form-control intime">  </th>
                    <th width="3%"> <input type="text" name="att[SEO067rrr][ot]" class="form-control outtime">  </th>
                    <th width="3%"> <input type="text" name="att[SEO067rrr][lt]" class="form-control lt"> </th>
                    <th width="3%"> <input type="text" name="att[SEO067rrr][ovrtime]" class="form-control ovrtime">  </th>
                    <th width="3%"> <input type="text" name="att[SEO067rrr][aa]" class="form-control">  </th>
                    <th width="3%"> <input type="text" name="att[SEO067rrr][twt]" class="form-control twt">  </th>
                    </tr>
                    <tr>
                        <th width="2%">4</th>
                        <th width="10%"> WEB001 / suresh </th>
                    <input  style="display:none" type="text" name="att[emp_id]" value='WEB001'  hidden="">
                    <th  width="5%" style="display:none"><input type="text" name="att[dt]" class="form-control date-pic-choose" readonly="" hidden=""> </th>
                    <th width="5%" style="display:none"><input type="text" name="att[site]" class="form-control date-pic-choose" readonly="" hidden=""> </th>
                    <th width="7%"> <input type="text" name="att[WEB001][][site]" class="form-control site"> </th>
                    <th width="3%"> 
                        <input type="radio" name="att[WEB001][st]" value="p" id="attendance_0">P   
                        <input type="radio" name="att[WEB001][st]" value="a" id="attendance_0">A
                    </th>
                    <th width="7%"> <input type="text" name="att[WEB001][sh]" class="form-control sal"> </th>
                    <th width="3%"> <input type="text" name="att[WEB001][wt]" class="form-control intime">  </th>
                    <th width="3%"> <input type="text" name="att[WEB001][ot]" class="form-control outtime">  </th>
                    <th width="3%"> <input type="text" name="att[WEB001][lt]" class="form-control lt"> </th>
                    <th width="3%"> <input type="text" name="att[WEB001][ovrtime]" class="form-control ovrtime">  </th>
                    <th width="3%"> <input type="text" name="att[WEB001][aa]" class="form-control">  </th>
                    <th width="3%"> <input type="text" name="att[WEB001][twt]" class="form-control twt">  </th>
                    </tr>
                    </tbody>
            </table>
            <input class="btn btn-primary pull-right" type="submit" value="Submit">                                </form>                            </div>

上面的形式没有给出我所期望的多维数组。我需要的多维数组,如下所示

代码语言:javascript
运行
复制
            Array
            (
                [0] => Array
                    (
                        [emp_id] => WEB001
                        [dt] => 03/01/2014
                        [site] => 03/01/2014
                         ...
                    )
                 [1] => Array
                    (
                        [emp_id] => WEB002
                        [dt] => 03/01/2014
                        [site] => 03/01/2014
                      ...
                    )
                 [2] => Array
                    (
                        [emp_id] => WEB002
                        [dt] => 03/01/2014
                        [site] => 03/01/2014
                    )

                .....
            )

注意:动态生成的表单

EN

回答 1

Stack Overflow用户

发布于 2014-01-03 22:12:57

我把你的表单按照你的意愿修改了一下(在每个输入标签元素的name属性中添加了一个索引),希望这能有所帮助:

代码语言:javascript
运行
复制
        <table width="60%" class="table table-striped table-bordered table-hover att  doodleTable">
                <thead>
                    <tr>
                        <th width="2%">ID</th>
                        <th width="10%"> Emp ID / Name </th>
            <!--                                        <th width="10%"></th>-->
                        <th width="3%">Site</th>
                        <th width="5%"> Attendance </th>
                        <th width="3%">Salary/hr</th>
                        <th width="5%">In time</th>
                        <th width="5%">Out time</th>
                        <th width="3%">Lunch Time</th>
                        <th width="3%">Over Time</th>
                        <th width="3%">Advance Amt</th>
                        <th width="3%">Total time</th>
                    </tr>
                </thead>
                <form method="POST" action="" accept-charset="UTF-8"><input name="_token" type="hidden" value="ZZVYZejVpAkVfjeTcs58q8JXwrcptOsinTNr6Xha">                                    <tbody>
                        <tr>
                            <th width="2%">2</th>
                            <th width="10%"> SEO067 / Nagaraj </th>
                    <input  style="display:none" type="text" name="att[0][emp_id]" value='SEO067'  hidden="">
                    <th  width="5%" style="display:none"><input type="text" name="att[0][dt]" class="form-control date-pic-choose" readonly="" hidden=""> </th>
                    <th width="5%" style="display:none"><input type="text" name="att[0][site]" class="form-control date-pic-choose" readonly="" hidden=""> </th>
                    <th width="7%"> <input type="text" name="att[0][SEO067][][site]" class="form-control site"> </th>
                    <th width="3%"> 
                        <input type="radio" name="att[0][SEO067][st]" value="p" id="attendance_0">P   
                        <input type="radio" name="att[0][SEO067][st]" value="a" id="attendance_0">A
                    </th>
                    <th width="7%"> <input type="text" name="att[0][SEO067][sh]" class="form-control sal"> </th>
                    <th width="3%"> <input type="text" name="att[0][SEO067][wt]" class="form-control intime">  </th>
                    <th width="3%"> <input type="text" name="att[0][SEO067][ot]" class="form-control outtime">  </th>
                    <th width="3%"> <input type="text" name="att[0][SEO067][lt]" class="form-control lt"> </th>
                    <th width="3%"> <input type="text" name="att[0][SEO067][ovrtime]" class="form-control ovrtime">  </th>
                    <th width="3%"> <input type="text" name="att[0][SEO067][aa]" class="form-control">  </th>
                    <th width="3%"> <input type="text" name="att[0][SEO067][twt]" class="form-control twt">  </th>
                    </tr>
                    <tr>
                        <th width="2%">3</th>
                        <th width="10%"> SEO067rrr / Nagaraj </th>
                    <input  style="display:none" type="text" name="att[1][emp_id]" value='SEO067rrr'  hidden="">
                    <th  width="5%" style="display:none"><input type="text" name="att[1][dt]" class="form-control date-pic-choose" readonly="" hidden=""> </th>
                    <th width="5%" style="display:none"><input type="text" name="att[1][site]" class="form-control date-pic-choose" readonly="" hidden=""> </th>
                    <th width="7%"> <input type="text" name="att[1][SEO067rrr][][site]" class="form-control site"> </th>
                    <th width="3%"> 
                        <input type="radio" name="att[1][SEO067rrr][st]" value="p" id="attendance_0">P   
                        <input type="radio" name="att[1][SEO067rrr][st]" value="a" id="attendance_0">A
                    </th>
                    <th width="7%"> <input type="text" name="att[1][SEO067rrr][sh]" class="form-control sal"> </th>
                    <th width="3%"> <input type="text" name="att[1][SEO067rrr][wt]" class="form-control intime">  </th>
                    <th width="3%"> <input type="text" name="att[1][SEO067rrr][ot]" class="form-control outtime">  </th>
                    <th width="3%"> <input type="text" name="att[1][SEO067rrr][lt]" class="form-control lt"> </th>
                    <th width="3%"> <input type="text" name="att[1][SEO067rrr][ovrtime]" class="form-control ovrtime">  </th>
                    <th width="3%"> <input type="text" name="att[1][SEO067rrr][aa]" class="form-control">  </th>
                    <th width="3%"> <input type="text" name="att[1][SEO067rrr][twt]" class="form-control twt">  </th>
                    </tr>
                    <tr>
                        <th width="2%">4</th>
                        <th width="10%"> WEB001 / suresh </th>
                    <input  style="display:none" type="text" name="att[2][emp_id]" value='WEB001'  hidden="">
                    <th  width="5%" style="display:none"><input type="text" name="att[2][dt]" class="form-control date-pic-choose" readonly="" hidden=""> </th>
                    <th width="5%" style="display:none"><input type="text" name="att[2][site]" class="form-control date-pic-choose" readonly="" hidden=""> </th>
                    <th width="7%"> <input type="text" name="att[2][WEB001][][site]" class="form-control site"> </th>
                    <th width="3%"> 
                        <input type="radio" name="att[2][WEB001][st]" value="p" id="attendance_0">P   
                        <input type="radio" name="att[2][WEB001][st]" value="a" id="attendance_0">A
                    </th>
                    <th width="7%"> <input type="text" name="att[2][WEB001][sh]" class="form-control sal"> </th>
                    <th width="3%"> <input type="text" name="att[2][WEB001][wt]" class="form-control intime">  </th>
                    <th width="3%"> <input type="text" name="att[2][WEB001][ot]" class="form-control outtime">  </th>
                    <th width="3%"> <input type="text" name="att[2][WEB001][lt]" class="form-control lt"> </th>
                    <th width="3%"> <input type="text" name="att[2][WEB001][ovrtime]" class="form-control ovrtime">  </th>
                    <th width="3%"> <input type="text" name="att[2][WEB001][aa]" class="form-control">  </th>
                    <th width="3%"> <input type="text" name="att[2][WEB001][twt]" class="form-control twt">  </th>
                    </tr>
                    </tbody>
            </table>
            <input class="btn btn-primary pull-right" type="submit" value="Submit">                                </form>                            </div>
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/20898119

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档