[英]Laravel form with two buttons get value of clicked button on submit
I have a view with two buttons, when clicking on one of the two buttons I want to receive the value of that button.我有一个带有两个按钮的视图,当单击两个按钮之一时,我想接收该按钮的值。
<form action="{{ url('selectMode') }}" method="post">
{{csrf_field()}}
<button class="card mt-3"><i class="fas fa-laptop my-pr"></i>Computer<label>
<input hidden name="mode" value="1">
</label></button>
<br>
<button class="card-disabled mt-3"><i class="fas fa-user my-pr"></i>Person<label>
<input hidden name="mode" value="2">
</label></button>
</form>
This is the code I have so far.这是我到目前为止的代码。 When dumping the request in the controller the value is always '2'.在控制器中转储请求时,该值始终为“2”。 What should I do to make this work?我应该怎么做才能使这项工作?
Blade file:刀片文件:
<form action="{{ route('store') }}" method="POST">
<button type="submit" name="status" value="approve">Approve</button>
<button type="submit" name="status" value="decline">Decline</button>
<button type="submit" name="status" value="reject">Reject</button>
</form>
Controller:控制器:
public function store(Request $request)
{
switch ($request->input('status')) {
case 'approve':
// Redirect to approve page
break;
case 'decline':
// Redirect to decline page
break;
case 'reject':
// Redirect to reject page
break;
}
}
You can give a value a button你可以给一个按钮一个值
<button type="input" value="value">
or input a type button或输入类型按钮
<input type="button" value="value">
https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/button https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/button
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.