【问题标题】:Save many values in one checkbox laravel在一个复选框中保存多个值 laravel
【发布时间】:2018-08-06 06:11:41
【问题描述】:

我有一个表格,显示公共/文件夹中的所有文件,

格式名称为 1_CCA-2018-0182224-720422085426

  1. 1_CCA-2018-0182224这是帐户 ID

  2. 720422085426这是身份证号

当用户选中复选框时,我想将文件名保存到 2 列(帐户 ID 和 ID NO)
我用 hidden 来获取 ID NO 值,但问题是 ID NO 的值与文件名不匹配,

如果我加厚最后一条记录,ID NO会在最后一条记录之前保存ID NO,

但是如果第一个记录很厚,ID NO保存正确,

谁能帮助我?

<table id="dataTable" class="table table-bordered table-condensed table-hover table-striped" width="100%" border="1">
    <thead>
    <tr>
        <th width="5%">No</th>
        <th width="45%">Account ID & ID No</th>
        <th data-checkbox="true" width="5%"></th>
    </tr>
    </thead>
    <tbody>
    <?php $i = 1; ?>
    <tr>
        <td>1</td>
        <td>123</td>
        <td>
            <input type="checkbox" name="account_id[]" value="{{ substr($file,10,18) }}">
            <input type="hidden" name="file[]" value="{{$file}}">
            <input type="hidden" name="id[]" value="{{ substr($file,29,12) }}">
        </td>

    </tr>
    <tr>
        <td>2</td>
        <td>1234</td>
        <td>
            <input type="checkbox" name="account_id[]" value="{{ substr($file,10,18) }}">
            <input type="hidden" name="file[]" value="{{$file}}">
            <input type="hidden" name="id[]" value="{{ substr($file,29,12) }}">
        </td>

    </tr>
    <?php $i++; ?>
    </tbody>
</table>

【问题讨论】:

    标签: php jquery laravel checkbox multichoiceitems


    【解决方案1】:

    您应该能够使用以下方法同步数据检索:

    foreach($request->id as $key => $value) {
        $id = $value;
        $file = $request->file[$key];
        $accountId = $request->account_id[$key] ?? null;
        if ($accountId) {
            // do stuff if checkbox was ticked
        } else {
            // do stuff if checkbox wasn't ticked            
        }
    }
    

    【讨论】:

      猜你喜欢
      • 2018-02-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多