Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Toggle Bootstrap modal with php trigger

I need to trigger a Bootstrap modal if a PHP GET url is set but I don't know how to.

The PHP code look's like this:

<?php
if ($_GET['activate']) {
$activate = $_GET['activate'];
    mysql_query("UPDATE `users` SET `active` = 1 WHERE `email_code` = '$activate'");
}
?>

After the mysql query but still in the if I need the modal to trigger. I've considered json but don't know enough to create my own code. The javascript to show the modal is this line:

$('#myModal').modal('show')

How would I translate that to work with my PHP trigger?

like image 254
justanotherhobbyist Avatar asked Feb 07 '26 03:02

justanotherhobbyist


1 Answers

Add a variable that checks the state,

$show_modal = false;

And in your get set it to true,

if ($_GET['activate']) {
    $activate = $_GET['activate'];
    mysql_query("UPDATE `users` SET `active` = 1 WHERE `email_code` = '$activate'");
    $show_modal = true;
}

Now in your html :

<?php if($show_modal):?>
  <script> $('#myModal').modal('show');</script>
<?php endif;?>
like image 104
Patsy Issa Avatar answered Feb 12 '26 05:02

Patsy Issa



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!