如何从“提交”按钮获取值数据以验证切换案例功能中的值?在这里,您可以从我的观点中脱颖而出。
{{Form::open(['route' => ['mgmtgroups_approvel', 'test' => $grouprequest->group_name]])}}
Create User {{$grouprequest->username}} in Group {{$grouprequest->group_name}} ?
{!! Form::submit('Yes',['class' => 'btn btn-default', 'name' => 'submitbutton', 'value' => 'save'])!!}
{!! Form::submit('No',['class' => 'btn btn-default', 'name' => 'submitbutton', 'value' => 'nosave'])!!}
{!! Form::close() !!}
这是我的带有开关盒功能的控制器功能。
public function setGroupApprovel(Request $request){
switch($request->submitbutton) {
case 'save':
$groups_create_subscription = new GroupSubscription();
$groups_create_subscription->idgroups = $request->input('idgroup');
$groups_create_subscription->subscriber = $request->input('iduser');
$groups_create_subscription->save();
break;
case 'nosave':
$groups_request = new GroupRequest();
$groups_request->iduser::find($request->iduser);
$groups_request->request_active = 0;
$groups_request->save;
break;}
目前不使用开关盒功能。也许该功能无法读取带有“保存”和“否保存”的提交值?
答案 0 :(得分:1)
您可以在方法中使用$request->get('submitbutton')
:
例如:
public function setGroupApprovel(Request $request)
{
switch ($request->get('submitbutton')) {
case 'save':
$groups_create_subscription = new GroupSubscription();
$groups_create_subscription->idgroups = $request->input('idgroup');
$groups_create_subscription->subscriber = $request->input('iduser');
$groups_create_subscription->save();
break;
case 'nosave':
$groups_request = new GroupRequest();
$groups_request->iduser::find($request->iduser);
$groups_request->request_active = 0;
$groups_request->save;
break;
}
}
我使用:
<input id='submit' class="btn btn-default" type='submit' name = 'submitbutton' value = 'save'>
<input id='submit' class="btn btn-default" type='submit' name = 'submitbutton' value = 'nosave'>
而不是:
{!! Form::submit('Yes',['class' => 'btn btn-default', 'name' => 'submitbutton', 'value' => 'save'])!!}
{!! Form::submit('No',['class' => 'btn btn-default', 'name' => 'submitbutton', 'value' => 'nosave'])!!}