MDB5 alert (not jscript alertbox) show after executing a php script?

Viewed 98

I got MDBootstrap5 UI 2.0 v2.0.0 Pro. I use it for my website and now I have build a shopping cart script for my "shop". I wanna show the alert I made when someone delete an item in the cart. I was using an alertbox in javascript before but now I want to use the alert from MDB5.

Here is the link to the docs for Alerts on MDB5 -> https://mdbootstrap.com/docs/standard/components/alerts/ (I know code and example are hidden but you can access it by source code lol .. yeah xd)

Here is my code:

<!-- Alerts -->
<div class="alert fade" id="alert-primary" role="alert" data-color="warning" data-position="top-center" data-stacking="true" data-width="535px" data-append-to-body="true" data-hidden="true" data-autohide="true" data-delay="3000">
  <i class="fas fa-exclamation-circle pr-3"></i> Item have been removed from your cart
</div>

<?php
if (isset($_GET['action'])) {
  if ($_GET['action'] == 'delete') {
    foreach ($_SESSION['cart'] as $key => $value){
      if ($value['item_id'] == $_GET['id']) {
        unset($_SESSION['cart'][$key]);
        echo "<script>
        triggersBasic.forEach(function (trigger, index) {
        let instance = mdb.Alert.getInstance(document.getElementById(instancesBasic[index]));
        document.getElementById(trigger).addEventListener('click', function () {
          instance.show();
        });
        });
        </script>";
        echo "<script>$('.alert').show()</script>";
      }
    }
  }
}
?>

I really don't know how to show the alert ... I can show it with a button pressed so I tried using same code but its not working.

0 Answers
Related