<?php if ($_POST['kkk']) { echo 123; } ?> <form action="" id="form" method="post"> <input type="submit" name="kkk" onclick="myFunction()" value="power" /> </form> <script> function myFunction() { alert("Hello! I am an alert box!"); } </script> 

When using the alert method, a confirmation window pops up, I press ok in it, after that the form flies away and I get an answer - 123. I need to do the same through a sweet alert.

 <?php if ($_POST['kkk']) { echo 123; } ?> <form action="" id="form" method="post"> <input type="submit" name="kkk" onclick="myFunction()" value="power"/> </form> <script> function myFunction() { Swal.fire( 'Good job!', 'You clicked the button!', ); } </script> 

Here sweetalert2. The page is immediately updated, without confirmation by the button ok, the answer is -123. It is necessary that the form be sent after clicking the success button.

Here's another option, everything is pressed in it, the page is updated, but there is no answer 123, it seems that the post did not come from the button.

 <?php if ($_POST['kkk']) { echo 123; } ?> <form id="form" action="" method="post"> <input type="submit" name="kkk" value="power" /> </form> <script> document.getElementById('form').addEventListener('submit', function(e) { var form = this; e.preventDefault(); // <--- prevent form from submitting swal({ title: "Are you sure?", text: "bla bla bla", icon: "success", buttons: [ 'No, cancel it!', 'Yes, I am sure!' ], dangerMode: true, }).then(function(isConfirm) { if (isConfirm) { swal({ title: 'ok!', text: 'bla blab bla!', icon: 'success' }).then(function() { form.submit(); // <--- submit form programmatically }); } else { swal("Cancelled", "error", "error"); } }) }); </script> 

on bootstrap is not quite that, but as an option ...

 <button type="button" class="btn btn-primary" data-toggle="modal" data-target="#exampleModalCenter"> Запустить модальное окно </button> <div class="modal fade" id="exampleModalCenter" 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"> ... </div> <div class="modal-footer"> <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button> <form action="" method="post"> <input class="btn btn-primary" type="submit" name="lol" value="ok" data-toggle="modal" data-target="#exampleModalCenter"> </form> </div> </div> </div> </div> <?php if ($_POST['lol']) { echo 123;} ?> 

    0