laravel 如何在laravel中从按钮到控制器获取数据属性的值
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/45188503/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to get value of data attribute from button to controller in laravel
提问by The Rock
How can we get the data attribute value from button to controller in laravel My button
我们如何在laravel我的按钮中从按钮到控制器获取数据属性值
<input type="submit" value="Add click" name="submit" id="submit" data-name="{{$value->name}}" data-click="{{$value->click}}">
i want to get data-click
and data-name
pass it to controller
我想获取data-click
并将其data-name
传递给控制器
$click=data-click;
$name=data-name;
from button attribute after submit form to controller
从提交表单到控制器后的按钮属性
But the result not get the data-name and data-click value. How can we try this??
但结果没有得到数据名称和数据点击值。我们怎样才能试试这个??
采纳答案by Anant Singh---Alive to Die
If you want to post those two data through Normal Form Post.Then use hidden input
fields:-
如果您想通过普通表单发布这两个数据。然后使用hidden input
字段:-
<input type="hidden" value="{{$value->name}}" name="data-name"/>
<input type="hidden" value="{{$value->click}}" name="data-click"/>
Or:-
或者:-
{{ Form::hidden('data-name', $value->name) }}
{{ Form::hidden('data-click', $value->click) }}
Now on Controller side you will get it as :-
现在在控制器方面,您将获得它:-
$request->input('data-name')
$request->input('data-click');
回答by Anand Pandey
You can use hidden field for this or you have to use ajax.
您可以为此使用隐藏字段,或者您必须使用 ajax。
@if ($value != '')
{{ Form::hidden('somevalue', $value->name) }}
{{ Form::hidden('somevalueclick', $value->click) }}
@endif