0

I am working on tabled based web form. Each row has separate datum . after filling my form all fields it should be grouped as an associative array in php. But i'm not getting exact result after many trials . enter image description here

Generated form

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

the above form didn't give what am expecting as an multidimensional array. My required multidimensional array as follows

            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
                    )

                .....
            )

Note : the form generating dynamically

1 Answer 1

2

I post your form modified as you wish (added an index to the name attribute of every input tag elements), hope this help:

        <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>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.