Beji
Beji

Reputation: 103

How to open external stored modal on page load

I have a modal for signing in user and would like to show it automatically on special pages if the user is not logged in. The modal is stored in an external file (modal_sign_in.php) so that I can call it from different pages.

Code of the link in menu bar:

<a href="" id="modal_sign_in" data-modal-external-file="modal_sign_in.php"
data-target="modal_sign_in" class="promoted">Login Modal</a>

How can I display the modal from any page on load checking if the user is logged in?

if ( $_SESSION['logged_in'] != 1 ) {       
    ??????
    exit();
}

Upvotes: 0

Views: 71

Answers (1)

GMX
GMX

Reputation: 26

You simply include that external file in there :

if ( isset($_SESSION['logged_in']) {   
  if ( $_SESSION['logged_in'] != 1 ) {           
    include("modal.php");
  }
}

If the modal does not trigger automaticly , you ill need to trigger it, with javascript. Create a button, change visibility to hidden, then connect that btn to the modal, and then you trigger the click.

if ( $_SESSION['logged_in'] != 1 ) {       
    include("modal.php");
    echo "<script> $( '#yourbtnid' ).trigger( 'click' ); </script> ";
}

Upvotes: 1

Related Questions