I am having an issue where in a website i am working on a form will not run the code when the button is pressed, this litterally worked and i have no idea what changed that broke it.
<form action="{{action('AdminAdminResponsibleController@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
Route::post('admin/viewPatient/assign', 'AdminAdminResponsibleController@assign');
code that i am trying to run, the dd is for testing, it never even gets there
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']);
}
I just updated this post with changes i made to the code
3
Answers
This has been resolved, there was an unclosed form tag elsewhere in the page
changed to
Have you tried changing the action to route?:
https://laravel.com/docs/6.x/helpers#method-route
/>
php artisan cache:clear
in your terminal.php artisan route:cache
in your terminal.Wait, your button is outside of your form!!
You need to use an input tag instead of a button tag.