[英]Laravel get table row values
I need help on getting the email value of the specific row that I selected. 我需要有关获取所选特定行的电子邮件值的帮助。 For example i selected the 3rd row button, then I will be able to get the value of the 3rd row email.
例如,我选择了第三行按钮,那么我将能够获取第三行电子邮件的值。
<table class="table table-striped">
@foreach($users as $user)
<tr>
<td class="col-md-2">
{!! $user->id !!}
</td>
<td class="col-md-2">
{!! $user->name !!}
</td>
<td class="col-md-2">
<input type="hidden" value="{!! $user->email !!}"> {!! $user->email !!}
</td>
<td class="col-md-3">
<input type="submit" class="btn btn-success btn-md" value="GET VALUE">
</td>
</tr>
@endforeach
</table>
Controller Code 控制器代码
public function getData(){
return var_dump($_POST);
}
Whats happening now is whenever I click the button, I always get the email of the last row of the table. 现在发生的事情是,每当我单击按钮时,我总是会收到表格最后一行的电子邮件。 Any Idea how to do this guys?
任何想法如何做这些家伙?
<table class="table table-striped">
@foreach($users as $user)
<form method="POST" action="your_controller_function_route">
<tr>
<td class="col-md-2">
{!! $user->id !!}
</td>
<td class="col-md-2">
{!! $user->name !!}
</td>
<td class="col-md-2">
<input type="hidden" name="email" value="{!! $user->email !!}"> {!! $user->email !!}
</td>
<td class="col-md-3">
<input type="submit" id ="sub{{ $user->id }}" class="btn btn-success btn-md" value="GET VALUE">
</td>
</tr>
</form>
@endforeach
</table>
try this 尝试这个
I got this conclusion as I understood 据我了解,我得出了这个结论
Try this. 尝试这个。 My demo for you is work in this way
我的演示为您工作
<table class="table table-striped">
@foreach($users as $user)
<form method="POST" name="email{!! $user->id !!}" action="function_to_print_data">
<tr>
<td class="col-md-2">
{!! $user->id !!}
</td>
<td class="col-md-2">
{!! $user->name !!}
</td>
<td class="col-md-2">
<input type="hidden" name="email" value="{!! $user->email !!}"> {!! $user->email !!}
</td>
<td class="col-md-3">
<input type="submit" class="btn btn-success btn-md" value="GET VALUE">
</td>
</tr>
</form>
@endforeach
</table>
You need to wrap each user table row with a form of its own. 您需要用自己的形式包装每个用户表行。 If not then the last row will overwrite the previous others since every user is wrapped in a single form.
如果不是,那么最后一行将覆盖之前的其他行,因为每个用户都以一种形式包装。
I cant get the form outside the < tr >. 我无法在<tr>之外获取表格。 If i do the button submit is not working.
如果我这样做按钮提交不起作用。 I was able to make it work by putting it inside the < td >
通过将它放在<td>中,我可以使它起作用
<table class="table table-striped">
@foreach($users as $user)
<tr>
<td class="col-md-2">
{!! $user->id !!}
</td>
<td class="col-md-2">
{!! $user->name !!}
</td>
<td class="col-md-2">
{!! $user->email !!}
</td>
<td class="col-md-3">
<form method="POST" action="/users/getData">
<input type="hidden" name="email" value="{!! $user->email !!}">
<input id= "{!! $user->email !!}" type="submit" class="btn btn-success btn-md" value="GET VALUE">
{{ csrf_field() }}
</form>
</td>
</tr>
@endforeach
</table>
But i dont think this is the best approach for the form. 但是我不认为这是表格的最佳方法。 But now its working this way.
但是现在它以这种方式工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.