Search code examples
phphtmlcss

how to call a modal from another php file when i click my link in my home page


How to call modal from another php file? Sorry I am just starting to learn wed development.

enter image description here


Solution

  • Considering this is a bootstrap modal (which it looks like it is), you can create a JavaScript function and echo it out in PHP. Something like this:

    echo '<script type="text/javascript">',
     '$("#modal-id").modal("toggle")',
     '</script>';
    

    The example above is form the Bootstrap 4 Docs where it demonstrates calling the modal from javascript. Once that script is echoed from your PHP, it'll run on the page and load the modal.

    To Clarify: Even if this isn't a bootstrap modal, you can still use the same JavaScript technique to add/remove a class to the modal which you can style to make it show/hide.