сгруппированный ассоциативный массив из формы HTML с php

0

Я работаю над созданной на основе веб-формы. Каждая строка имеет отдельную привязку. после заполнения моей формы все поля он должен быть сгруппирован как ассоциативный массив в php. Но я не получаю точный результат после многих испытаний. Изображение 174551

Сгенерированная форма

            <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>

приведенная выше форма не давала того, что ожидается как многомерный массив. Мой требуемый многомерный массив следующим образом

            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
                    )

                .....
            )

Примечание: форма, генерирующая динамически

Теги:
html-form

1 ответ

2

Я публикую вашу форму, измененную по вашему желанию (добавленный индекс к атрибуту имени каждого элемента входных тегов), надеюсь, что эта помощь:

        <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>

Ещё вопросы

Сообщество Overcoder
Наверх
Меню