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

从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

图片转代码服务由CSDN问答提供 功能建议

我想通过点击提交获取foreach中的model_id []值,但我从model_id []得到所有。

在我的表单中:

 &lt; form id =“modify”class =“form-horizo​​ntal”method =“POST”action =“  {{route('modifymodel')}}“
 onsubmit =”return confirm('你确定要这样做吗?');“&gt; 
 {!!  csrf_field()!!} 
&lt; table class =“table-hover”width =“100%”cellpadding =“5”cellspacing =“0”&gt; 
 @foreach($ data_model as $ key =&gt; $  va)
&lt; tr&gt; 
&lt; td width =“30px”&gt; {{++ $ key}}&lt; / td&gt; 
&lt; td width =“280px”&gt; 
&lt;输入 type =“hidden”id =“model_id []”name =“model_id []”value =“{{$ va-&gt; model_id}}”&gt; 
&lt; input type =“text”name =“txt_depmo”  id =“txt_depmo”style =“width:280px;”
 value =“{{$ va-&gt; model_name}}”&gt; 
&lt; / td&gt; 
&lt; td&gt; 
&lt;输入类型 =“submit”class =“btn btn-outline-primary”name =“submit”id =“submit”value =“Updates”&gt; 
&lt; input type =“submit”class =“btn btn-outline-danger  “name =”submit“id =”submit“value =”Removes“&gt; 
&lt; / td&gt; 
&lt; / tr&gt; 
 @endforeach 
&lt; / table&gt; 
&lt; / form&gt; \  n   
 
 

我的控制器:

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

但我在model_id []中获得了所有数组的结果。

  [“1”,“3”,“8”,“9”  ] 
   
 
 

我想通过点击按钮获取ID

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

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
    
    已采纳该答案
    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题