Не удается опубликовать данные HTML-запроса на контроллере - PullRequest
1 голос
/ 03 октября 2019

У меня проблема с тем, что на веб-сайте, где я работаю над формой, код не запускается при нажатии кнопки, это буквально сработало, и я понятия не имею, что изменило, что сломало его.

<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

    Route::post('admin/viewPatient/assign', 'Admin\AdminResponsibleController@assign');

код, который я пытаюсь запустить, дд для тестирования, он даже не попадает туда

 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']);
}

Я только что обновил этот пост с изменениями, которые я сделал вкод

Ответы [ 4 ]

0 голосов
/ 03 октября 2019

конец формы конец формы для отправки

<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>
0 голосов
/ 03 октября 2019

Вам нужно использовать тег ввода вместо тега кнопки.

<input type="submit" value="Submit">
0 голосов
/ 03 октября 2019

Это было решено, в другом месте на странице был открыт закрытый тег формы

<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>
0 голосов
/ 03 октября 2019

Вы пытались изменить действие на маршрут?:

 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>
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...