我遇到的问题是,在网站上,当我按下一个按钮时,我正在处理表单的网站将无法运行代码,这在后来还是行得通的,而且我不知道是什么更改使它中断了。
<form action="{{action('Admin\AdminResponsibleController@assign')}}" method="post" id="assignParty">
@csrf
First name: <input type="text" name="fname"><br>
Last name: <input type="text" name="lname"><br>
email: <input type="text" name="email"><br>
@if ($message = Session::get('success'))
<div class="alert alert-success alert-block">
<button type="button" class="close" data-dismiss="alert">×</button>
</div>
@endif
@if ($message = Session::get('message'))
<div class="alert alert-warning alert-block">
<button type="button" class="close" data-dismiss="alert">×</button>
<strong>{{ $message }}</strong>
</div>
@endif
<input type="radio" name="party_type" value="responsible" checked>Responsible Party<br>
<input type="radio" name="party_type" value="responsibleTwo"> Second Responsible Party<br>
<input type="radio" name="party_type" value="witness"> Witness <br>
<input type="checkbox" name="remove" value="remove"> Remove Selected Assignment <br>
<input type="hidden" id="userId" name="userId" value="<?php echo $user->id; ?>">
</form>
<button type="submit" form="assignParty" value="Submit">Submit</button>
路线
Route::post('admin/viewPatient/assign', 'Admin\AdminResponsibleController@assign');
我正在尝试运行的代码,dd用于测试,甚至从未到达过
public function assign(Request $request)
{
dd('hit');
if($request->input('userId') != null){
$patient = intval($request->input('userId'));
$patient = User::where('id', $patient)->first();
} /**/
$party = User::where('email', $request->input('email'))
// We want to be sure that Admins and Patients can't be responsible parts, if they need to be we can create another account for them
// Having patients be able to be repsonsible parties would confuse the patient and could lead to buggy code
->first();
if($party != null){
if($party->user_type == 'Admin' || $party->user_type == 'Patient'){
return redirect()->back()->with(['message', 'Can not assign this user']);
}
}
// setup remove user variable as false
$removeUser = false;
// if the email is null, remove user is true
if($request->input('remove') != null){
$removeUser = true;
} else if($request->input('email') == null){
return redirect()->back()->with(['message', 'Please include an email']);
}
// switch case to switch to different statements based on the input of party_type
switch ($request->input('party_type')) {
case 'responsible':
$this->check($request, $party, 'responsible_party', 'Responsible Party', $removeUser, $patient);
break;
case 'responsibleTwo':
$this->check($request, $party, 'responsible_party_two', 'Second Responsible Party', $removeUser, $patient);
break;
case 'financial':
$this->check($request, $party, 'financial', 'Financially Responsible Party', $removeUser, $patient);
break;
case 'legal':
$this->check($request, $party, 'legal', 'Legal Rep', $removeUser, $patient);
break;
case 'witness':
$this->check($request, $party, 'witness', 'Witness', $removeUser, $patient);
break;
default:
// in future versions please include a link to dispatch a support request
// this really shouldn't happen, but a default case should be included in case something somehow goes wrong
throw new \Exception('You must provide a party type.');
break;
}
// return to the view with a message that the party has been assigned
return redirect()->back()->with(['success', 'Party Updated sucessfully']);
}
我刚刚用对代码的更改更新了这篇文章
答案 0 :(得分:0)
您是否尝试过将动作更改为路线?
Route::post('admin/viewPatient/assign', 'Admin\AdminResponsibleController@assign')->name('assign.post');
<form action="{{route('assign.post')}}" method="post" enctype="multipart/form-data" id="assignParty">
https://laravel.com/docs/6.x/helpers#method-route
/>
php artisan cache:clear
。php artisan route:cache
。<form>
inputs
<button type="submit" form="assignParty" value="Submit">Submit</button>
</form>
答案 1 :(得分:0)
您需要使用输入标签而不是按钮标签。
<input type="submit" value="Submit">
答案 2 :(得分:0)
此问题已解决,页面其他位置未关闭表单标签
<form action="{{action('Patient\UploadController@adminUpload')}}" method="post" enctype="multipart/form-data">
@csrf
<input type="file" name="file" id="file">
<input id="user" type="hidden" class="form-control" name="user" value="{{$user->id}}" required autofocus>
<input type="submit" value="Upload File" name="submit">
<span class="text-danger">{{$errors->first('file')}}</span>`enter code here`
更改为
<form action="{{action('Patient\UploadController@adminUpload')}}" method="post" enctype="multipart/form-data">
@csrf
<input type="file" name="file" id="file">
<input id="user" type="hidden" class="form-control" name="user" value="{{$user->id}}" required autofocus>
<input type="submit" value="Upload File" name="submit">
</form>
<span class="text-danger">{{$errors->first('file')}}</span>
答案 3 :(得分:0)
结束表单提交表单
<form action="{{action('Admin\AdminResponsibleController@assign')}}" method="post" id="assignParty">
@csrf
First name: <input type="text" name="fname"><br>
Last name: <input type="text" name="lname"><br>
email: <input type="text" name="email"><br>
@if ($message = Session::get('success'))
<div class="alert alert-success alert-block">
<button type="button" class="close" data-dismiss="alert">×</button>
</div>
@endif
@if ($message = Session::get('message'))
<div class="alert alert-warning alert-block">
<button type="button" class="close" data-dismiss="alert">×</button>
<strong>{{ $message }}</strong>
</div>
@endif
<input type="radio" name="party_type" value="responsible" checked>Responsible Party<br>
<input type="radio" name="party_type" value="responsibleTwo"> Second Responsible Party<br>
<input type="radio" name="party_type" value="witness"> Witness <br>
<input type="checkbox" name="remove" value="remove"> Remove Selected Assignment <br>
<input type="hidden" id="userId" name="userId" value="<?php echo $user->id; ?>">
<button type="submit" form="assignParty" value="Submit">Submit</button>
</form>