Reputation: 413
How can we get the data attribute value from button to controller in laravel My button
<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
$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??
Upvotes: 3
Views: 9788
Reputation: 72289
If you want to post those two data through Normal Form Post.Then use hidden input
fields:-
<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');
Upvotes: 4
Reputation: 2025
You can use hidden field for this or you have to use ajax.
@if ($value != '')
{{ Form::hidden('somevalue', $value->name) }}
{{ Form::hidden('somevalueclick', $value->click) }}
@endif
Upvotes: 2