Problems sending form in modal bootstrap

Asked

Viewed 344 times

1

Hello, I am sending a form that is in a modal inside a page, however the modal simply does not send, it is in a page that is a return of an ajax (a search in the case), I do not know if it influences.

<div class="modal fade" id="finalizarMonitoramento{{$m->ID_CD_INTERNACAO}}" tabindex="-1" role="dialog" aria-labelledby="exampleModalCenterTitle" aria-hidden="true">
    <div class="modal-dialog modal-dialog-centered" role="document">
      <div class="modal-content">
        <div class="modal-header">
          <h5 class="modal-title" id="exampleModalLongTitle">Modal title</h5>
          <button type="button" class="close" data-dismiss="modal" aria-label="Close">
            <span aria-hidden="true">&times;</span>
          </button>
        </div>
        <div class="modal-body">
        <form action="{{url('monitoramento/finalizaMonitoramento')}}" method="post">
        <input type="hidden" value="{{$m->ID_CD_MONITORAMENTO}}" id="id_mot" name="id_mot">
           @method('PUT')
           @csrf
          <input type="submit" class="btn btn-primary" value="enviar">
        </form>
        </div>
        <div class="modal-footer">
          <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>

        </div>

      </div>
    </div>
  </div> 

this is the modal, when I send simply nothing happens. Some hint?

That is the route:

Route::put('/finalizaMonitoramento','MonitoramentoController@finalizaMonitoramento');
  • Tested whether the url and the token are generating correctly? And the route of the form, with her is?

  • They are being generated yes, the route of the form is correct, the fact is that simply nothing happens when I send the form.

  • You can add your route to the question?

  • Already added, check if there is any error please

  • Just one more question, you use some route name prefix?

  • yes 'monitoring', the problem is not in the route, the problem is that the form is not sent, no error occurs.

  • You can try this https://stackoverflow.com/questions/31686089/form-submit-button-not-working-in-bootstrap-modal-window to answer your question, unfortunately I won’t have time to reproduce the error to try to help you

  • What is the possibility of having some JS with preventDefault in the Submit of this form? Because from what I understand the form is not being submitted, correct?

  • No possibility, what I realized when I inspected the element is that the form opens and closes with nothing inside, the buttons stay out

  • What’s inside your Controller?

  • Check the network tab of the browser dev tools, confirm that there is the sending of the package in the form Submit. If there is no, the context of the doubt changes. If there is, already see which is the package’s answer to know the error.

Show 6 more comments

1 answer

0

an alternative to this would be to use the Laravel Collective ( https://laravelcollective.com/docs/5.4/html ), Yes, I imagine the problem as already mentioned in the comments is the Token.

PS: The Collective Laravel needs to be installed as seen at this link.

Example of what Form would look like:

<div class="modal fade" id="finalizarMonitoramento{{$m->ID_CD_INTERNACAO}}" tabindex="-1" role="dialog" aria-labelledby="exampleModalCenterTitle" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered" role="document">
  <div class="modal-content">
    <div class="modal-header">
      <h5 class="modal-title" id="exampleModalLongTitle">Modal title</h5>
      <button type="button" class="close" data-dismiss="modal" aria-label="Close">
        <span aria-hidden="true">&times;</span>
      </button>
    </div>
    <div class="modal-body">
    {!! Form::open(['url' => 'monitoramento/finalizaMonitoramento', 'method' => 'POST']) !!}
     {{Form::hidden('_method','PUT')}}
     {{Form::hidden('id_mot', $m->ID_CD_MONITORAMENTO, 'id' => 'id_mot')}}
      {{Form::submit('enviar', ['class'=>'btn btn-primary'])}}
    {!! Form::close() !!}
    </div>
    <div class="modal-footer">
      <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
    </div>
  </div>
</div>

Recalling that the {{Form::hidden('_method','PUT')}} was inserted to show the upload that this request is of type PUT.

I hope I’ve helped.

  • Apparently your Hospitalization ID field is getting out of FORM I don’t know if this might be impacting on functionality as well.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.