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;
?>'''
Related
I am using bootstrap modal to show to data which is fetched from the database. I have this code for load remote PHP data into bootstrap modal. it is work. but i need to add a loading message into the modal until data fetch from database. I have this code for load remote PHP data into bootstrap modal box
index.html
<script>
$(document).ready(function(){
$('#myModal').on('show.bs.modal', function (e) {
var rowid = $(e.relatedTarget).data('id');
$.ajax({
type : 'post',
url : 'fetch_subjects.php', //Here you will fetch records
data : 'rowid='+ rowid, //Pass $id
success : function(data){
$('.fetched-data').html(data);//Show fetched data from database
}
});
});
});
</script>
<!-- Modal -->
<div class="modal fade" id="myModal" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">Subjects</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<div class="fetched-data"> </div> <!--fetched dates here -->
</div>
<div class="modal-footer">
<button type="butZton" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
fetch_subjects.php
<?php
require 'db_connection.php';
if($_POST['rowid']) {
$id = $_POST['rowid'];
$sql = "SELECT * FROM subject where year=$id";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
echo "<div class='list-group'>
<b>
<a href='notes?id=". $row['id'] ."' class='list-group-item list-group-item-action' target='_blank'>
" . $row["name"]. "
</a>
</b>
</div>
</button>";
}
}
else {
echo "no details.";
}
}
?>
I would do that this way:
$.ajax({
type : 'post',
url : 'fetch_subjects.php', //Here you will fetch records
data : 'rowid='+ rowid, //Pass $id
success : function(data){
$('.fetched-data').html(data);//Show fetched data from database
},
beforeSend: function() {
$('#loader').show(); // Assuming that you have some loader defined
},
complete: function(){
$('#loader').hide(); //Hide this loader
},
});
<script>
$(document).ready(function(){
$('#myModal').on('show.bs.modal', function (e) {
var rowid = $(e.relatedTarget).data('id');
$.ajax({
type : 'post',
url : 'fetch_subjects.php', //Here you will fetch records
data : 'rowid='+ rowid, //Pass $id
beforeSend: function() {
$('.loader').show(); // Assuming that you have some loader defined
},
success : function(data){
$('.fetched-data').html(data);//Show fetched data from database
$('.loader').hide();
},
});
});
});
</script>
<!-- Modal -->
<div class="modal fade" id="myModal" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">Subjects</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<!-- loader -->
<div class="loader">
loading.............
</div>
<div class="fetched-data"> </div> <!--fetched dates here -->
</div>
<div class="modal-footer">
<button type="butZton" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
I am trying to insert the signature image data into the database and failed. I just found out how to pass the signature image into the folder in pc and i can see every image have different 'name.png' in the folder and i am thinking that the 'name.png' can be save in the database. I do not know how to make it successfully save into database.
This is my code of signature pad which i make it in a modal:
<div class="row mb-4">
<a href="#" class="btn btn-lg btn-success" data-toggle="modal" data-target="#basicModal">Client
Signature</a>
</div>
</div>
<div class="modal fade" id="basicModal" tabindex="-1" role="dialog" aria-labelledby="basicModal"
aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title" id="myModalLabel">Client Signature</h4>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<div id="signArea" >
<h2 class="tag-ingo" style="font-size:30px;color:blue">Put signature below,</h2>
<div class="typed" ></div>
<p align="center">
<canvas class="sign-pad" id="sign-pad" width="300" height="100"></canvas></p>
</div>
</div>
<div class="modal-footer">
<button input="reset" class="btn btn-secondary" >Reset</button>
<button id="btnSaveSign" type="submit" name="submit" class="btn btn-primary">Submit</button>
This is the code that i save my signature image into a folder:
<script>
jQuery(document).ready(function() {
Main.init();
FormElements.init();
});
$(document).ready(function() {
$('#signArea').signaturePad({drawOnly:true, drawBezierCurves:true, lineTop:90});
});
$("#btnSaveSign").click(function(e){
html2canvas([document.getElementById('sign-pad')], {
onrendered: function (canvas) {
var canvas_img_data = canvas.toDataURL('image/png');
var img_data = canvas_img_data.replace(/^data:image\/(png|jpg);base64,/, "");
//ajax call to save image inside folder
$.ajax({
url: 'save_sign.php',
data: { img_data:img_data },
type: 'post',
dataType: 'json',
success: function (response) {
window.location.reload();
}
});
}
});
});
</script>
This is the save-sign.php code:
<?php
$result = array();
$imagedata = base64_decode($_POST['img_data']);
$filename = md5(date("dmYhisA"));
//Location to where you want to created sign image
$file_name = './doc_signs/'.$filename.'.png';
file_put_contents($file_name,$imagedata);
$result['status'] = 1;
$result['file_name'] = $file_name;
echo json_encode($result);
?>
And this is the code where i retrieve the image in the folder:
<img src="<?php echo $image; ?>" class="sign-preview" />
The database name is 'appointment, and the image data should be in 'imagename'
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 want to select from a list of data and display the result of the selected data in a modal popup. i just can't figure out how to pass the id to the popup so i can display the result. HELP!!
<td> <button class="btn btn-primary " data-toggle="modal" data-id="<?php $id= $row['id'] ?>" data-target="#myModal" <?php echo"id=$row[id]'";?> >
View Details
</button>
</td>
the modal popup
<div class="modal fade" id="myModal" 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>
<h4 class="modal-title" id="myModalLabel">Requisition Details</h4>
</div>
<div class="modal-body">
<?php
$id = $_GET['id'];
include('mysql_connect.php');
$query11 = mysql_query ("select * from p_requisition where id = '$id' ") or die(mysql_error());
$rows= mysql_fetch_array($query11);
echo $rows['details'];
?>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Save changes</button>
</div>
</div>
<!-- /.modal-content -->
</div>
<!-- /.modal-dialog -->
</div>
Firstly, add class to button may be get-data,
then in jquery,
$(document).ready(function() {
$(document).on("click",".get-data"function(){
var val = $(this).attr("data-id");
$.ajax({
url: "path to ajax file",
type: "POST",
dataType: "HTML",
async: false,
success: function(data) {
$('.modal-body').html(data);
}
});
});
});
in ajax file,write query to fetch data from mysql, manipulate the data and display in popup.
ajax.php
<?php
$id = $_POST['id'];
include('mysql_connect.php');
$query11 = mysql_query ("select * from p_requisition where id = '$id' ") or die(mysql_error());
$rows= mysql_fetch_array($query11);
echo $rows['details'];// here you need to manipulate the database data with html and pass it on to popup.
?>
use like
<td>
<button class="btn btn-primary" onclick='openModel(<?php echo"id=$row[id]";?>') >View Details</button>
</td>
open your model like
<script>
function openModel(modelId,rowId){
$('#'+modelId).model('open');
//Ajax call to get data for speciefic id
}
</script>
I think you should use ajax call, when open modal like this:
Your modal:
<div class="modal fade" id="myModal" 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>
<h4 class="modal-title" id="myModalLabel">Requisition Details</h4>
</div>
<div class="modal-body">
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Save changes</button>
</div>
</div>
<!-- /.modal-content -->
</div>
<!-- /.modal-dialog -->
</div>
Your button:
<button class="btn btn-primary " data-toggle="modal" data-id="<?php echo $row['id'] ?>" data-target="#myModal" id="myButton">
View Details
</button>
When click the button, show the modal:
$('#myButton').click(function() {
$('#myModal').modal('show')
});
If the modal shown, you pass the data with ajax
$('#myModal').on('shown.bs.modal', function(e) {
$.ajax({
method: "POST",
url: "getData.php",
data: {
dataId: $('#myModal').attr('data-id')
},
success: function(data) {
data = jQuery.parseJSON(data);
$('.modal-body', '#myModal').html(data);
}
});
})
Your getData.php like this
<?php
//dataId comes from ajax (POST)
$id = filter_input(INPUT_POST, 'dataId');
include('mysql_connect.php');
$query11 = mysql_query("select * from p_requisition where id = '$id' ") or die(mysql_error());
$rows = mysql_fetch_array($query11);
//you should use json_encode, and you can parse when get back data in ajax
echo json_encode($rows['details']);
My goal is to open the details of a link in the loop $viewhh with an ID in a modal. I have tried so many different ways through jquery, etc and have not been able to get anything to work. Just calling the page works fine, but trying to load in a modal has been futile for me.
<div class="row">
<div class="col-md-12">
<p><a class="btn btn-default" href="add_praise.php" role="button">Add a Praise</a></p>
<h2>Praises</h2>
<p><?php
$query = "SELECT praise.id, praise.title, praise.description, praise.created, member.username FROM praise INNER JOIN member ON praise.member_id=member.id ORDER BY praise.created desc;";
$stmt = $db->query($query);
printf('<table class="table">');
printf('<thead><tr><th>Title</th><th>Posted By</th><th>Posted</th></tr></thead>');
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
$created = date('m-d-Y', strtotime($row['created']));
$viewhh = '<a href="view_praise.php?id=' .
urlencode($row["id"]) . '">' . ($row["title"]) . '</a>';
printf("<tbody><tr><td> %s </td> <td> %s </td><td> %s </td><td> %s </td></tr></tbody>", $viewhh, htmlentities($row["username"]), $created, $viewbutton);
printf("</table");
}
?> </p>
</div>
This is the page being called
<?php
$praiseid = urldecode($_GET['id']);
$sth = $db->prepare("select * from praise where id = '$praiseid'");
$sth->execute();
$result = $sth->fetch(PDO::FETCH_ASSOC);
$title = $result['title'];
$description= $result['description'];
?>
<div class="container">
<!-- Example row of columns -->
<div class="row">
<div class="col-md-4">
<h2><?php echo $title; ?></h2>
<div><?php echo $description; ?></div>
</div>
</div>
I have tried adding this but only get the first record now.
<script>
$(function () {
$("#loadpraise").colorbox({ iframe: true, width: "90%", height: "90%", closeButton: false });
$("#events").colorbox({
onOpen: function () { alert("Colorbox onOpen"); },
onLoad: function () { alert("Colorbox onLoad"); },
onComplete: function () { alert("Colorbox onComplete"); },
onCleanup: function () { alert("Colorbox onCleanup"); },
onClosed: function () { alert("Colorbox onClosed"); }
});
$("#childForm").colorbox({ closeButton: false, onClosed: function () { alert($.colorbox.popupResult) } });
});
</script>
I got it working using BootStrap 3 modal.
The link calling the record: just added data-toggle="modal" and data-target="#myModal"
$viewpraise = '<a data-toggle="modal" href="view_praise.php?id=' . urlencode($row["id"]) . '" data-target="#myModal">' . ($row["title"]) . '</a>';
included the modal for remote call on the same page. The remote page is loaded into the "modal-content" div.
<!-- Modal -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
</div> <!-- /.modal-content -->
</div> <!-- /.modal-dialog -->
</div> <!-- /.modal -->
Then on the page called add the rest of the modal content:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title>Remote file for Bootstrap Modal</title>
<script>
$('body').on('hidden.bs.modal', '.modal', function () {
$(this).removeData('bs.modal');
});</script>
</head>
<body>
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title">Modal title</h4>
</div> <!-- /modal-header -->
<div class="modal-body">
<h2><?php echo $title; ?></h2>
<div><?php echo $description; ?></div>
</div> <!-- /modal-body -->
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<!-- <button type="button" class="btn btn-primary">Save changes</button>-->
</div> <!-- /modal-footer -->
</body>
</html>