简体   繁体   中英

Get value from array textbox in 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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM