I have this line of PHP:
$STRING .= $b_f.''.$CORE->_e(array('head','5','flag_link')).''.$b_a;
This url opens now as a new webpage. How can i open it as a dialog/modal window instead? In my code i have bootstrap installed.
Try this "trick":
Open modal
<div id="popupModal2" class="modal hide fade" tabindex="-1" role="dialog">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h3>Title</h3>
</div>
<div class="modal-body">
<iframe src="" style="zoom:0.60" frameborder="0" height="250" width="99.6%"></iframe>
</div>
<div class="modal-footer">
<button class="btn" data-dismiss="modal">OK</button>
</div>
</div>
and the js:
$('.bootpopup').click(function(){
var frametarget = $(this).attr('href');
var targetmodal = $(this).attr('target');
if (targetmodal == undefined) {
targetmodal = '#popupModal';
} else {
targetmodal = '#'+targetmodal;
}
if ($(this).attr('title') != undefined) {
$(targetmodal+ ' .modal-header h3').html($(this).attr('title'));
$(targetmodal+' .modal-header').show();
} else {
$(targetmodal+' .modal-header h3').html('');
$(targetmodal+' .modal-header').hide();
}
$(targetmodal).on('show', function () {
$('iframe').attr("src", frametarget );
});
$(targetmodal).modal({show:true});
return false;
});
Just pass your link to the button's href.
DEMO
Related
I have a modal script that I created in php and the script works fine but the php closing tag ?> is not closing at the end, tried putting the script in the header using echo but then the script dose not work at all also tried using just php removing the Script tags that did not work been working on for a while any help would be greatly appreciated.
<?php
include("db_config.php");
include('includes/session.inc');
$Title = _('Check Inquiry');
$ViewTopic = 'AccountsPayable';
$BookMark = 'AccountsPayable';
include('includes/header.inc');
include('includes/SQL_CommonFunctions.inc');
echo '<link href="' . $RootPath . '/css/bootstrap.min.css" rel="stylesheet" type="text/css" />';
echo '<script src = "'.$RootPath.'/javascripts/jquery.min.js"></script>';
echo '<script type="text/javascript" src = "'.$RootPath.'/javascripts/bootstrap.min.js"></script>';
$query = "select * from banktrans where type=".'22';
$result = mysqli_query($con, $query);
while($row = mysqli_fetch_array($result)){
$transID = $row['transno'];
echo "<tr>";
echo "<td><button data-id='".$transID."' class='btn btn-info btn-sm btn-popup'>Details</button></td>";
echo "</tr>";
}
echo <<<'HTML'
<!-- Modal -->
<div class="modal fade" id="custModal" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title">Check Details</h4>
<button type="button" class="close" data-dismiss="modal">×</button>
</div>
<div class="modal-body">
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
<script type="text/javascript">
$(document).ready(function () {
$('.btn-popup').click(function () {
var transno = $(this).data('id');
$.ajax({
url: 'get_check_data.php',
type: 'post',
data: { transno: transno },
success: function (response) {
$('.modal-body').html(response);
$('#custModal').modal('show');
}
});
});
});
</script>
HTML;
include('includes/footer.inc');
?>
Yes it dose appear I added the HTML in a separate php file and it works but the closing tag ?> is still not working as expected normally it shows up in NP++ in red when closed but shows as normal text but does not appear on page I am just wondering if it will create any issues that way.
Here is the code for the include modal.php
echo <<<'HTML'
<!-- Modal -->
<div class="modal fade" id="custModal" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title">Check Details</h4>
<button type="button" class="close" data-dismiss="modal">×</button>
</div>
<div class="modal-body">
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
<script type="text/javascript">
$(document).ready(function () {
$('.btn-popup').click(function () {
var transno = $(this).data('id');
$.ajax({
url: 'get_check_data.php',
type: 'post',
data: { transno: transno },
success: function (response) {
$('.modal-body').html(response);
$('#custModal').modal('show');
}
});
});
});
</script>";
HTML;
?>'''
The pdf's are uploaded in the s3 bucket and by using its link, i want to display it. They are being downloaded in firefox and chrome. What to do?
<!-- Modal -->
<div class="modal fade" id="myModal" role="dialog" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title" id="myModalLabel">Document</h4>
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
</div>
<div class="modal-body">
<object data="[PDF link]">
<iframe src="[PDF link]&embedded=true"></iframe>
</object>
</div>
<div class="modal-footer">
<button type="button" class="btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
$(function () {
var fileName = "Youpdfwithextension";//or path of pdf with extenstion
$("#btnShow").click(function () {
$("#dialog").dialog({
modal: true,
title: fileName,
width: 540,
height: 450,
buttons: {
Close: function () {
$(this).dialog('close');
}
},
open: function () {
var object = "<object data=\"{FileName}\" type=\"application/pdf\" width=\"500px\" height=\"300px\">";
object += "If you are unable to view file, you can download from here";
object += " or download <a target = \"_blank\" href = \"http://get.adobe.com/reader/\">Adobe PDF Reader</a> to view the file.";
object += "</object>";
object = object.replace(/{FileName}/g, "Files/" + fileName);
$("#dialog").html(object);
}
});
});
});
<input id="btnShow" type="button" value="Show PDF" />
<div id="dialog" style="display: none">
</div>
I am trying to open details data obtained from php-mysql in a model box instead of a new html page. Currently it is opening in other html page but I want to add that in a model box.
Here is my current code:
<a class="btn btn-info" href="details.php?view_id=<?php echo $row['userID']; ?>" title="click for Details" onclick="details.php"><span class="glyphicon glyphicon-eye-open"></span> Show Details</a>
here it refers to details.php?view_id but model example found with id selector like bellow,
Show Details
<div id="openModal" class="modalDialog">
X
<div>
X
<h2>Modal Box</h2>
</div>
</div>
How I can add href="details.php?view_id=" instead of #openModel ??
I am new learner, please help.
function edit_m_id(str){
var xhttp;
document.getElementById("edit_con_tent").innerHTML = "<center>loading.......</center>";
xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
document.getElementById("edit_con_tent").innerHTML = this.responseText;
}
};
xhttp.open("GET", "edit_m_con.php?q="+str, true);
xhttp.send();
}
Edit
<div id="small-modal" class="modal fade" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Modal Header</h4>
</div>
<div class="modal-body">
<span id='edit_con_tent'></span>
<p>Some text in the modal.</p>
</div>
<div class="modal-footer"><button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
i have a page(products.php) that has a table which is dynamically populated. Each row has a button that opens up a modal, but in order to pass params to the modal: firstly, i declared the modal on the current page(products.php). Secondly, i call up the rest of the modal using ajax from another page(modal.php). i've popuplated all options in a select drop down before using ajax, but i can't seem to do the same this time by displaying the modal. i can use php href but that causes my jquery script that i use in submitting to the database on my modal not to work anymore and that's why i thought up doing this through ajax. I would like to know why this isn't working with well ajax.
Heres a sample code:
products.php
<html>
<header>
<script>
function modalValues(val1,val2){
if(window.XMLHttpRequest){
xhttp = new XMLHttpRequest();
}else{
xhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xhttp.onreadystatechange = function(){
if(xhttp.readyState == 4 && xhttp.status == 200){
document.getElementById("load_here").innerHTML = xhttp.responseText;
}
};
xhhtp.open("POST","modal.php?id3="+val1+"&id="+val2,true);
xhttp.send();
}
</script>
</header>
<body>
<div class="modal fade" data-keyboard="false" id="product_customerModal" tabindex="-1" role="dialog" aria-labelledby="product_customerModalLabel" aria-hidden="true">
<div class="modal-dialog modal-lg">
<div id="load_here" class="modal-content">
</div>
</div>
</div>
<table>
<?php
global $link;
$query = "blah,blah";
$result_set = mysqli_query($link,$query);
$number = mysqli_num_rows($result_set);
for($count=0;$count<$number;$count++){
$result = mysqli_fetch_array($result_set);
echo "<tr>";
echo "<td>{$result['field1']}</td>";
echo "<td>{$result['field2']}</td>";
echo "<td><button onclick='modalValues(<?php echo $result['field1'];?>,<?php echo $result['field2'];?>) data-toggle="modal" data-target='#product_customerModal'></button></td>";
}
?>
</table>
</body>
</html>
And
modal.php
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title" > Date: (<?php echo $date;?>)</h4></div
<div class="modal-body">
<?php
//some php code
?>
<div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
You need to correct two lines they are as follows and then your model html will be there:
xhttp.open("POST","test2.php?id3="+val1+"&id="+val2,true); not xhttp
echo "<td><button onclick='modalValues('".$result['field1']."','".$result['field2']."') data-toggle='modal' data-target='#product_customerModal'></button></td>";
I'm trying to loop through an array of videos and create a button/modal combo for each. I'm having an issue with the need for id="myModal". Each video's button links to the same video. How would I go about keeping these unique? I've tried changing id to class, but that wasn't working.
<?php foreach ($thisVideos as $video):?>
<button class="btn btn-primary link">Video</button>
<div id="myModal" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
</div>
<div class="modal-body">
<iframe width="400" height="300" frameborder="0" allowfullscreen=""></iframe>
</div>
</div>
</div>
</div>
<script>
$('.link').click(function () {
var src = 'http://www.youtube.com/v/<?=$video["entry_data"]["video-id"]?>';
$('#myModal').modal('show');
$('#myModal iframe').attr('src', src);
});
$('#myModal button').click(function () {
$('#myModal iframe').removeAttr('src');
});
</script>
<?php endforeach; ?>
Your approach is wrong, you only need one modal element and one script (and one event handler...) so you put these outside of the loop. You can add the url in a data attribute in your video list and then you can do everything you need to do.
A simple example with your code:
<?php foreach ($thisVideos as $video): ?>
<button class="btn btn-primary link"
data-url="http://www.youtube.com/v/<?=$video["entry_data"]["video-id"]?>">Video</button>
<?php endforeach; ?>
<div id="myModal" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
</div>
<div class="modal-body">
<iframe width="400" height="300" frameborder="0" allowfullscreen=""></iframe>
</div>
</div>
</div>
</div>
<script>
$('.link').click(function () {
// get the url from the data attribute
var src = $(this).data('url');
$('#myModal').modal('show');
$('#myModal iframe').attr('src', src);
});
$('#myModal button').click(function () {
$('#myModal iframe').removeAttr('src');
});
</script>
May be this help you
<?php foreach ($thisVideos as $key=>$video):?>
..............
<div id="myModal_<?php echo $key; ?>" class="modal fade"
....................
..............
<script>
$('.link').click(function () {
var src = 'http://www.youtube.com/v/<?=$video["entry_data"]["video-id"]?>';
$('#myModal_<?php echo $key; ?>').modal('show');
$('#myModal_<?php echo $key; ?> iframe').attr('src', src);
});
$('#myModal_<?php echo $key; ?> button').click(function () {
$('#myModal_<?php echo $key; ?> iframe').removeAttr('src');
});
</script>
<?php endforeach; ?>
Hope you understand and it helps you.
Note Its not a good way.It just solves the way you want.
The trick is to have an unique id for #myModal and this can by done in so many different ways.
You can easily set a counter in your loop, for example,
$counter = $counter++;
Append
<div id="myModal_<?=$counter?>"
and in the js you should have
$('#myModal_<?=$counter?>')
This will give the video button link unique ids and all the video links will work.