简体   繁体   中英

Bootstrap modal and PHP GET

How to call bootsrtap modal using $_GET? I got a php file which going to send success or fail and receive in the index.php as $_GET. Id like to have bootstrap modal to pop up? How?

<?php
    if(isset($_GET['success']))
    {
        ?>
        <div class="modal fade" id="success" role="dialog">
        <?php
    }
    else if(isset($_GET['fail']))
    {
        ?>
        <div class="modal fade" id="fail" role="dialog">
        <?php
    }
    else
    {
        ?>
      Normal stuff put here

     <?php
    }
    ?>

I recommend not to implement the modal in way you are trying. It is a suggestion and upto you as how to implement it based on for what scenario you needed 2 different id. If you are going to create modal id based on conditions and then down the line in code you will need additional logic to know whether it was success modal or failure modal. If the modal is just to display a success/failure message then I recommend, create modal and add modal body message based on condition if(isset($_GET['success']))

ie 1 modal, 1 id, 1 message(success or failure based on $_GET)

Now for your original issue, did you just putted the one line ? Did you coded modal, content, body, footer ?

try this from example http://www.w3schools.com/bootstrap/bootstrap_modal.asp

If you have coded that then are you trying to invoke the modal on after page load or any button click or any other event ? for that simple use jQuery("#myModal_id").modal();

I have put information based on the code and description you mentioned.

You can't do this thing using php . You can do that in using some javascript along with php .

<script>
<?php
if (isset($_GET['success'])) {

    echo "var success = true;";

} else {

   echo "var success = false;";
}

?>

if (success) {

   $('#success').modal('show');

} else {

  $('#fail').modal('show');
}

</script>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM