skip to Main Content

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


  1. Chosen as BEST ANSWER

    This has been resolved, there was an unclosed form tag elsewhere in the page

    <form action="{{action('PatientUploadController@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`
    

    changed to

    <form action="{{action('PatientUploadController@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>
    

  2. Have you tried changing the action to route?:

     Route::post('admin/viewPatient/assign', 'AdminAdminResponsibleController@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

    • Also you should have the inputs closed like: />
    • you could try to run php artisan cache:clear in your terminal.
    • you could try to run php artisan route:cache in your terminal.

    Wait, your button is outside of your form!!

    <form>
       inputs
    
       <button type="submit" form="assignParty" value="Submit">Submit</button>
    </form>
    
    Login or Signup to reply.
  3. You need to use an input tag instead of a button tag.

    <input type="submit" value="Submit">
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search