lundi 4 septembre 2017

PHP array binding back with html form values

I have array of values which have a list called parameter_list which
has a set of values and those values need to be updated through a html form. Array values described given below.

array:2 [▼
  0 => {#289 ▼
    +"Group1Name": {#285 ▼
      +"test1id": {#281 ▼
        +"name": "test1name"
        +"external_lab": "labname"
        +"parameter_list": array:2 [▼
          0 => {#282 ▼
            +"parameter": "PHM"
            +"observed_value": ""
            +"unit": "pmol/mm"
            +"normal": ""
            +"min": ""
            +"max": ""
            +"ref_notes": ""
          }
          1 => {#283 ▼
            +"parameter": "PHM"
            +"observed_value": ""
            +"unit": "pmol/mm"
            +"normal": ""
            +"min": ""
            +"max": ""
            +"ref_notes": ""
          }
        ]
        +"attachments": {#284 ▶}
      }
      +"test2id": {#286 ▼
        +"name": "test2name"
        +"external_lab": "labname"
        +"parameter_list": array:1 [▼
          0 => {#287 ▼
            +"parameter": "PHM"
            +"observed_value": ""
            +"unit": "pmol/mm"
            +"normal": ""
            +"min": ""
            +"max": ""
            +"ref_notes": ""
          }
        ]
        +"attachments": {#288 ▶}
      }
    }
  }
  1 => {#295 ▼
    +"Group2Name": {#292 ▼
      +"test1id": {#290 ▼
        +"name": "TEST1"
        +"parameter_list": array:1 [▶]
      }
      +"test2id": {#293 ▼
        +"name": "TEST2"
        +"parameter_list": array:1 [▶]
      }
    }
  }
]

I made a loop through getting those values in a form by input tag as below,

 @foreach($valBookingDetails as $key => $val)
                                <?php $count=-1; ?>
                                @foreach($val->lab_appointment_details->test_details as $k=> $subVal)
                                    @foreach($subVal as $k2 => $sub2Val)
                                        <?php $count++; ?>
                                        <tr class="test-report-header">
                                            <td><input  type="checkbox" class="filled-in chk-blood-main-item" id="chkFullBloodReport" /> <label for="chkFullBloodReport" class="lbl-for-checkbox" style="padding: 8px;">&nbsp;</label></td>
                                            <td class="test-report-header-title">

                                                </td>
                                            <td></td>
                                            <td><textarea type="text" class="text-center testlab-report-textarea materialize-textarea" style="visibility: hidden;"  ></textarea></td>
                                            <td><span class="hide">mmg</span></td>
                                            <td><span class="hide">12 - 15</span></td>
                                            <td><textarea type="text" class="text-center testlab-report-textarea materialize-textarea" style="visibility: hidden;"  ></textarea></td>
                                            <td>
                                                <input multiple="true" type="file" id="upload1" class="testlab-report-upload" accept=".jpg,.jpeg,.png,.gif,.pdf" />
                                                <div class="uploaded-report-container">
                                                    <span class="img-addMore"><img src="<?php echo url('../images/addMore.png');?>" /></span>
                                                </div>
                                            </td>
                                        </tr>

                                        @foreach($sub2Val as $k3=> $sub3Val)
                                            <input type="hidden" name="groupname[<?php echo $k2?>][]" value="<?php echo $sub3Val->name; ?>">
                                            <?php $spancount=0; ?>
                                            @foreach($sub3Val->parameter_list as $k4=> $sub4Val)
                                                <input type="hidden" name="groupname[<?php echo $k2?>][<?php echo $k4 ?>][param]" value="<?php echo $sub4Val->parameter; ?>">
                                                <input type="hidden" name="groupname[<?php echo $k2?>][<?php echo $k4 ?>][test]" value="<?php echo $sub3Val->name; ?>">
                                            <tr>
                                                <td><input type="checkbox" class="filled-in chk-blood-items" id="chkHemoglobinBloodReport" /><label for="chkHemoglobinBloodReport" class="lbl-for-checkbox" style="padding: 8px;">&nbsp;</label></td>
                                                @if($spancount == 0)
                                                    <?php $spancount++; ?>
                                                <td class="word-wrap" rowspan="">
                                                    </td>
                                                @endif
                                                <td></td>
                                                <td><textarea type="text" class="text-center testlab-report-textarea materialize-textarea"  ></textarea></td>
                                                <td> </td>
                                                <td><textarea type="text" class="text-center testlab-report-textarea materialize-textarea"  ></textarea></td>
                                                <td><textarea type="text" class="text-center testlab-report-textarea materialize-textarea"  ></textarea></td>
                                                <td>
                                                    <input multiple="true" type="file" id="upload2" class="testlab-report-upload" accept=".jpg,.jpeg,.png,.gif,.pdf" />
                                                    <div class="uploaded-report-container">
                                                        <span class="img-addMore"><img src="<?php echo url('../images/addMore.png');?>" /></span>
                                                    </div>
                                                </td>
                                            </tr>
                                                @endforeach
                                            @endforeach
                                        @endforeach
                                    @endforeach
                                @endforeach

I want to get back the same array with the new updated values through form. But it is not forming as it is the array which i retrieved.

I want to form the array like below by using html form,

array:2 [▼
  0 => {#289 ▼
    +"Group1Name": {#285 ▼
      +"test1id": {#281 ▼
        +"name": "test1name"
        +"external_lab": "labname"
        +"parameter_list": array:2 [▼
          0 => {#282 ▼
            +"parameter": "APHM"
            +"observed_value": "23.32"
            +"unit": "pmol/mm"
            +"normal": "12"
            +"min": "243"
            +"max": "22"
            +"ref_notes": "this test is counduct based on ..."
          }
          1 => {#283 ▼
            +"parameter": "PHM"
            +"observed_value": "12.3"
            +"unit": "pmol/mm"
            +"normal": "23"
            +"min": "34.3"
            +"max": "234.34"
            +"ref_notes": "this test is counduct based on ..."
          }
        ]
        +"attachments": {#284 ▶}
      }
      +"test2id": {#286 ▼
        +"name": "test2name"
        +"external_lab": "labname"
        +"parameter_list": array:1 [▼
          0 => {#287 ▼
            +"parameter": "PHM"
            +"observed_value": "12.3"
            +"unit": "pmol/mm"
            +"normal": "34.3"
            +"min": "344"
            +"max": "345"
            +"ref_notes": "this test is counduct based on ..."
          }
        ]
        +"attachments": {#288 ▶}
      }
    }
  }
  1 => {#295 ▼
    +"Group2Name": {#292 ▼
      +"test1id": {#290 ▼
        +"name": "TEST1"
        +"parameter_list": array:1 [▶]
      }
      +"test2id": {#293 ▼
        +"name": "TEST2"
        +"parameter_list": array:1 [▶]
      }
    }
  }
]

Please help me to rebind the form values as it is in the array.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire