douji3426
2017-08-01 07:30
浏览 66

如何获取用户选择的按钮值并在laravel 5.4中的控制器上使用它

I am new with php and laravel and I have a problem:

How to get a button value chosen by the user and use it on the controller to retrieve specific information from database.

I get the "termkey" from the database and I need to know the value selected by the user.

This is my view :

view

controller

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

我是php和laravel的新手,我遇到了问题:

如何获取用户选择的按钮值并在控制器上使用它来从数据库中检索特定信息。

我从数据库中获取“termkey”,我需要知道值 由用户选择。

这是我的观点:

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • duancaiyi7567 2017-08-01 07:36
    已采纳
    <button name="termkey">{{ $ca->termkey }}</button>
    

    change the upper to

    <button name="termkey" value="{{ $ca->termkey }}">{{ $ca->termkey }}</button>
    

    then in controller

    $request->input('termkey');
    
    点赞 评论
  • dongruolin5324 2017-08-01 07:41

    you have to use value attribute in your button tag and why there is a closing anchor tag I don't understand. IN value attribute u can set any kind of value you want. then u can access it in the controller like you did

    <button type="submit" name="termKey" value="{{$c->termKey}} "><span class="badge">{{$c->total}}</span></button>
    

    And please always try to paste code not image

    点赞 评论

相关推荐 更多相似问题