How to open the modal bootstrap form after an Laravel 5.4 validation error

Asked

Viewed 678 times

1

I have a contact form in modal bootstrap. I have the validations where they are validating correctly. Now my question is: How do I stop when I do not pass the validation it return the message in modal with it open. When it validates and does not pass the validation it does not open the modal. So the client will never know that the form has been sent How’s my modal call: I have a view where I have the modal.blade.php in my index.blade.php I give a include in it and in my button where I activate the modal this way:

<div class="row">
  <div class="col-md-2 col-md-offset-3">
      <button type="button" data-toggle="modal"  
        data-target="#product_view" class="btn btn-default btn-lg">Clique aqui.</button>
  </div>
</div>

This butano calls it my modal. How do I call this modal in the controller?


  • Put all the code from Controller, View and Javascript! so it gets complicated to say something.

  • Dude I don’t know Jquery, but looking at how little I know that is almost nothing, can fix a thing. was just to do a @if(Session::has('errors')) and call the modal here hehehe. @endif

1 answer

2


Well, sorry for my lack of attention, but I don’t really have JS skills. Then I repaired the code, I saw that it returns a session with a variable Errors. So I simply gave an if checking if there really was a session variable. See:

@if(Session::has('errors'))
   e aqui dentro eu chamei o meu js.
@endif

As I said because I don’t know much about js, I know that there is a way to read the page first so that javascript can be executed. So soon I did :

$(document).read(funciona(){
    alert('Ops!! Teve erros no seu formulário. Vamos abrir novamente para que você possa corrigir. ;) ');
    $('#product_view').modal('show');
 });

And so solving my problem.

Browser other questions tagged

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