I cannot call modal error without clicking (Materialize)

Asked

Viewed 102 times

-1

I cannot call the modal without having to click the button. I would like a modal to appear according to the "Check availability" If true = modal appear with message that it has been successfully registered If return false = modal saying error.

 if (!empty($_POST['nome_prova'])){
        $prova = ($_POST['nome_prova']);
        $data_prova = explode('/',($_POST['data_prova']));
        $requerente = ($_POST['requerente']);
        $num_acessos = ($_POST['numero']);

        $data_prova = $data_prova[2].'-'.$data_prova[1].'-'.$data_prova[0];

        if ($reservas->VerificarDisponibilidade($prova, $data_prova, $requerente, $num_acessos)){
            $reservas->reservar($prova, $data_prova, $requerente, $num_acessos);
            MODAL DE SUCESSO AQUI
        } else {  
            ?>
             MODAL DE ERRO AQUI 
            <?php
     }

}

?>

 <!-- Modal Structure -->
  <div id="modal1" class="modal  modal-trigger">
    <div class="modal-content">
      <h4>Modal Header</h4>
      <p>A bunch of text</p>
    </div>
    <div class="modal-footer">
      <a href="#!" class="modal-close waves-effect waves-green btn-flat">Agree</a>
    </div>
  </div>

1 answer

0


Try it that way

<?

    if (!empty($_POST['nome_prova'])){
        $prova = ($_POST['nome_prova']);
        $data_prova = explode('/',($_POST['data_prova']));
        $requerente = ($_POST['requerente']);
        $num_acessos = ($_POST['numero']);

        $data_prova = $data_prova[2].'-'.$data_prova[1].'-'.$data_prova[0];

        if ($reservas->VerificarDisponibilidade($prova, $data_prova, $requerente, $num_acessos)){
            $reservas->reservar($prova, $data_prova, $requerente, $num_acessos);
?>
           <script>
        $(document).ready(function(){
            $("#modal1").modal();
        });
    </script>
        <? } else {  
            ?>
             <script>
        $(document).ready(function(){
            $("#modal2").modal();
        });
    </script>
            <?php
     }

}

?>

 <!-- Modal Structure -->
  <div id="modal1" class="modal  modal-trigger">
    <div class="modal-content">
      <h4>Modal Header</h4>
      <p>A bunch of text</p>
    </div>
    <div class="modal-footer">
      <a href="#!" class="modal-close waves-effect waves-green btn-flat">Agree</a>
    </div>
  </div>
  • Good morning Lucas, thank you so much for trying to help! But I still couldn’t. The modal just won’t open. When I put it to open by clicking the button opens normally. So I discarded something related to the js of materialize. I’m really not getting to open it with decision instead of clicking button

  • Exchange . modal(); for . modal('open'); or . modal('show');

Browser other questions tagged

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