Piet Maessen
Piet Maessen

Reputation: 47

how to show a php page in a modal

I was wondering if it is possible to catch a whole php page in a modal. It is about this situation: I have now an anchor which leads me to the page like this:

<a href="post.php?id=<?php echo $article['articleId']; ?>"><?php echo $article['title']; ?></a>

How can i put the whole content of, lets say, the page post.php?id=1 in a modal like this:

<button type="button" class="btn btn-info btn-lg" data-toggle="modal" data-target="#myModal">Open Modal</button>
<!-- Modal -->
<div class="modal fade" id="myModal" role="dialog">
  <div class="modal-dialog">

   <!-- Modal content-->
   <div class="modal-content">
    <div class="modal-header">
      <button type="button" class="close" data-dismiss="modal">&times;</button>
      <h4 class="modal-title">Modal Header</h4>
    </div>
    <div class="modal-body">
      <p>HERE SHOULD COME THE CONTENT OP THE PHP FILE</p>
    </div>
    <div class="modal-footer">
      <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
    </div>
  </div>

</div>

in post.php; these are the lines which parse the content:

<h3> <?php echo $article['title']; ?> </h3>
<p class="content article-content"> <?php echo nl2br($article['content']); ?> </p>

Upvotes: 1

Views: 2587

Answers (1)

delboy1978uk
delboy1978uk

Reputation: 12365

Using jQuery you can do something like this:

$('#modal-body').load('/your/url/here', {var1: val1, var2: val2}, function(){
    // show your modal here
});

See here for more info https://api.jquery.com/load/

Upvotes: 1

Related Questions