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
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Stata 面板数据模型选择
  • ¥20 idea运行测试代码报错问题
  • ¥15 网络监控:网络故障告警通知
  • ¥15 django项目运行报编码错误
  • ¥15 请问这个是什么意思?
  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services
  • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏
  • ¥15 模糊pid与pid仿真结果几乎一样
  • ¥15 java的GUI的运用