dskyx46424 2017-10-25 08:37
浏览 75
已采纳

从laravel中的数组文本框中获取值

I want to get model_id[] value in foreach by click submit but i get all from model_id[].

In my form:

<form id="modify" class="form-horizontal" method="POST" action="{{ route('modifymodel') }}"
      onsubmit="return confirm('Are you sure to do this?');">
    {!! csrf_field() !!}
    <table class="table-hover" width="100%" cellpadding="5" cellspacing="0">
        @foreach($data_model as $key=> $va)
            <tr>
                <td width="30px">{{++$key}}</td>
                <td width="280px">
                    <input type="hidden" id="model_id[]" name="model_id[]" value=" {{ $va->model_id }} ">
                    <input type="text" name="txt_depmo" id="txt_depmo" style="width: 280px;"
                           value="{{$va->model_name}}">
                </td>
                <td>
                    <input type="submit" class="btn btn-outline-primary" name="submit" id="submit" value="Updates">
                    <input type="submit" class="btn btn-outline-danger" name="submit" id="submit" value="Removes">
                </td>
            </tr>
        @endforeach
    </table>
</form>

My Controller:

public function modifymodel(Request $request){
   $modelidd=Input::get('model_id');
 }

but i got the result all array in model_id[].

["1","3","8","9"]

i want to get id from my button click

  • 写回答

1条回答 默认 最新

  • dream890110 2017-10-25 08:47
    关注

    Make form inside the loop. I will make the form for every item.

            @foreach($data_model as $key=> $va)
    
             <form id="modify" class="form-horizontal" method="POST" action="{{ route('modifymodel') }}"
                 onsubmit="return confirm('Are you sure to do this?');">
                 {!! csrf_field() !!}
                <table class="table-hover" width="100%" cellpadding="5" cellspacing="0">
                <tr>
                    <td width="30px">{{++$key}}</td>
                    <td width="280px">
                        <input type="hidden" id="model_id[]" name="model_id[]" value=" {{ $va->model_id }} ">
                        <input type="text" name="txt_depmo" id="txt_depmo" style="width: 280px;"
                               value="{{$va->model_name}}">
                    </td>
                    <td>
                        <input type="submit" class="btn btn-outline-primary" name="submit" id="submit" value="Updates">
                        <input type="submit" class="btn btn-outline-danger" name="submit" id="submit" value="Removes">
                    </td>
                </tr>
              </table>
             </form>
    
            @endforeach
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 关于加载卡的问题有能知道这个要怎么处理吗?
  • ¥100 rtmpose姿态评估
  • ¥15 java 通过反射找路径下的类,打包后就找不到
  • ¥15 通联支付网上收银统一下单接口
  • ¥15 angular有偿编写,
  • ¥15 centos7系统下abinit安装时make出错
  • ¥15 hbuildex运行微信小程序报错
  • ¥15 关于#python#的问题:我知道这个问题对你们来说肯定so easy
  • ¥15 wpf datagrid如何实现多层表头
  • ¥15 为啥画版图在Run DRC会出现Connect Error?可我Calibre的hostname和计算机的hostname已经设置成一样的了。