Basically, I am trying to have a user click a button on one php page and it will print a new php page. This function WORKS. The problem is I am trying to have the userID transferred over to the 2nd page and printed on the new page. However, for some reason this seems to be getting lost. When I alert the user# right before the get request is made, the # shows pops up. But when the new page appears in the printer dialog, the userID is missing. Any suggestions would be greatly appreciated.
Function from php page 1:
$("#printing").on('click',function(){
alert (user);
$.get("flyer.php", {userNow: user});
$('body').append('<iframe src="flyer.php?userNow" id="printIFrame" name="printIFrame"></iframe>');
$('#printIFrame').bind('load',
function() {
window.frames['printIFrame'].focus();
window.frames['printIFrame'].print();
}
);
});
php page 2:
<html>
<body>
<div class="wrapper">
<h1>Tai Chi</h1>
<h2>Sign Up Now!</h2>
<h3>Benefits of Tai Chi:</h3>
<ul>
<li>It enhances harmony between body and mind</li>
<li>It improves your internal energy level</li>
<li>Improves your muscle strength and endurance</li>
<li>Reduces back pain</li>
<li>Lowers daily stress</li>
<li>Can slow down the aging process</li>
</ul>
<div id="contact">For more information, please email R-adler#neiu.edu</div>
<div id="userID">
<? echo UserID.$user = $_GET['userNow'] ?>
</div>
</div>
</body>
Try to concatenate the user value like this:
$("#printing").on('click',function(){
alert (user);
$('body').append('<iframe src="flyer.php?userNow='+user+'" id="printIFrame" name="printIFrame"></iframe>');
$('#printIFrame').bind('load',
function() {
window.frames['printIFrame'].focus();
window.frames['printIFrame'].print();
}
);
});
Check also in the url if you get the uservalue passed there.
There is no value being passed in the GET array.
Use the link as flyer.php?userNow="+user
Related
I have WHMCS setup, and i am trying to make a message bubble that would show when someone access it with the specific link.
Like when someone access this link, they will see normal page - https://example.com/billing/clientarea.php?action=details
But if someone access https://example.com/billing/clientarea.php?action=details&status=incomplete
They will get a message.
I have already setup the message, and it is showing on the default link. But i do not know how to set it up on the 2nd link only? I am using WHMCS.
Can anyone guide me?
Code for message bubble.
<div class="alert alert-danger">
<strong>The following errors occurred:</strong>
<ul>
<li>Please enter your address and click on save to proceed. Once Saved, then only you will be able to access the client area.</li>
</ul>
</div>
EDIT: Solution Added
thanks a ton for your help #symlink, your method works on PHP, but for WHMCS/smarty php, it needs other code, a very simple code that too, lol.
{if $smarty.get.status eq incomplete}
{include file="$template/includes/alert.tpl" type="info" msg="Please fill the form to continue with our services."}
{else}
{/if}
If the $GET param exists, add a class to the message div that makes it appear:
PHP/HTML
<?php
$class = "";
if(isset($GET["status"]) && $GET["status"] === "incomplete"){
$class = "show";
}
?>
<div class="alert alert-danger <?php echo $class ?>">
<strong>The following errors occurred:</strong>
<ul>
<li>Please enter your address and click on save to proceed. Once Saved,
then only you will be able to access the client area.</li>
</ul>
</div>
CSS
.alert.alert-danger{
display: none;
}
.alert.alert-danger.show{
display: block;
}
If you edit templates, it makes it harder to keep your WHMCS up to date. I would recommend using a hook to output some JS to inject the appropriate alert to your page.
Perhaps the ClientAreaFooterOutput hook point? https://developers.whmcs.com/hooks-reference/output/#clientareafooteroutput
Something like:
<?php
add_hook('ClientAreaFooterOutput', 1, function($vars) {
$status = App::getFromRequest('status'); //This is handy and sanitised
return <<<HTML
jQuery(document).on('ready', function() {
if ('{$status}' == 'incomplete') {
//Add your code here to output the alert where you wish
}
});
HTML;
});
A number of employees and their info gets shown on a page. The info of employees gets retrieved via a DB and then a foreach() loop is used to display all employees who fit the search criteria, an example can be seen on image below
Now when the user clicks the button, a simple Bootstrap pop up modal gets triggered, with some basic form fields. As can be seen from example image below
My Problem
I need to get the $userID when a button is clicked to work with / process data in modal.
Below is an extract of relevant code:
$teacherClass = new TeacherSearch();
$teachers = $teacherClass->showAllTeachers();
if (is_array($teachers)) {
foreach ($teachers as $teacher) {
$src = $teacher['userID'];
<div class="teacher-info">
<p class="teacherLabel">
NAME:
<?php
echo $teacher['name'];
?>
</p>
<p class="teacherLabel">
HEADLINE:
<?php
echo $teacher['headline'];
?>
<p class="teacherLabel">
LOCATION:
<?php
echo $teacher['location']
?>
</p>
<!--BUTTON GOES HERE-->
}//foreach
What I've tried
Ive tried using an <a> element binding a parameter with userID to it, like so:
Hire <?php echo $teacher['name'] ?>
As is to be expected the following triggered a new page reload inside the modal.
I then tried using a # sign for ahref attribute and then biding parameter $userID to it like so:
The above lead to an undefined index error as can be seen in the picture above.
Conclusion
I hope this question makes sense, I'm pretty much out of ideas, no idea how to further approach this problem.
You add the user-id in the anchor tag.To get the contents of the attribute data-id you have to use
<a id="myid" data-id="123">link</a>
<script>
$('#myid').data("id");
</script>
use javascript function to get userID and show modal:
<a onclick="myfunction('<?php echo $userID; ?>')>Hire <?php echo $teacher['name'] ?></a>
javascript function:
var userID; // global
function myfunction(id){
userID = id;
$("#myModal").modal("show");
//do somethings with user id here
}
I am new to PHP and I am using session variables to create shopping cart, as I need to increment the number of items in the cart, I use session variables. However, this variable keep increment every time the page refreshed/reload, which increment the number of items.
<?php
session_start();
if (!isset($_SESSION['items'])){
$_SESSION['items'] = 0;
}
function increament_items(){
$_SESSION['items']++;
}
?>
and in HTML I have this
<a id="laptop" href="index.php" onclick="<?php increament_items() ?>",title="header=[Add to cart] body=[ ] fade=[on]">
I have tried to use form using post/get and still the same.
any help?
thanks
Php, as it is not a client language, will not work "onclick", but every time the code
<a id="laptop" href="index.php" onclick="<?php increament_items() ?>",title="header=[Add to cart] body=[ ] fade=[on]">
Is loaded.
So, you could use something like this to solve your problem.
1) Add at the end of your php code this:
if($_GET['add']==1){
increament_items();
}
2a) Then, replace your html code with this one
<a id="laptop" href="nameofyourphppage.php?add=1">Add</a>
2b) Or, if you prefer, after having included jquery library (*) into html page, use the following one:
<script>
function openLink(url)
{$("#add").html('Loading...');
$("#add").load(url, function (responseText, textStatus, req) {
if (textStatus == "error") {
$("#add").html('An error occurred');
}
});
}
</script>
<a id="laptop" href="javascript:openLink('nameofyourphppage.php?add=1')">Add</a>
<div id="add"></div>
The second solution will run the php code without the user leaving the html page.
(*)To include the jquery library, put into the head section of your html page this code:
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
I asked this question already but my friend said to take a different approach. Instead of constantly pinging the database when a new linked is clicked, he said to narrow down the php array to just the floor in question and convert it to an javascript object so that the data will be there and not have to keep grabbing it from the database.
This is what I'm trying to do - I have a floor map and an anchor tag over the seat and when it is click I want the information from the database to appear in another div above the map.
Now I have a php array with the specific floor but from what I have read that I need to convert it to json. Now how would I go about selecting the data of the seat that was clicked, grab the data from the json array and display it in the div above the map. I also want to have the data disappear when a different seat is selected and populate with the new information.
I want to target the the div with the seat# -> from there grab the information in the javascript -> display in the div above the map.
This is what I have:
<div id="information" style="display:none">
</div>
<div id="c324" class="seat seat-department">
<(a) class="trigger" onClick="document.getElementById('info').style.display='block';"></(a)></div>[2]
</div>
IF someone can point me in the right direction that would be great.
Thanks
You'd want to have a script tag that contains the data from your php array somewhere,
<script>
var myInfoStuf = {'c234': 'This is info on the seat'}; // an object of info strings
</script>
so, and then in your onclick, which I'd recommend breaking out into a function,
function displayInfoForDiv(id) {
document.getElementById('info').innerHTML = myInfoStuf[id];
document.getElementById('info').style.display='block';
return false;
}
and then you can invoke that onclick handler from you seat like:
<div id="c324" class="seat seat-department">
<class="trigger" onclick="displayInfoForDiv('c234')"></a>
</div>
Ok so I finally got what I need to work!!!!
this is what I did.
JS
var jsonData = <?php echo json_encode($array); ?>;
function displayInfoForDiv(i){
document.getElementById('fname').innerHTML = jsonData[i].first_name;
document.getElementById('lname').innerHTML = jsonData[i].last_name;
document.getElementById('ext').innerHTML = jsonData[i].extension;
document.getElementById('lvl').innerHTML = jsonData[i].level;
document.getElementById('seat').innerHTML = jsonData[i].seat;
document.getElementById('depart').innerHTML = jsonData[i].department;
document.getElementById('email').innerHTML = jsonData[i].email;
}
html
<div id="c234" class="seat">
<a class="trigger" onClick="displayInfoForDiv(22)"></a>
</div>
Hopefully this helps someone and they don't have to spend days trying to get it to work. Thanks again for all the help
NOTE: This is a long question. I've explained all the 'basics' at the top and then there's some further (optional) information for if you need it.
Hi folks
Basically last night this started happening at about 9PM whilst I was trying to restructure my code to make it a bit nicer for the designer to add a few bits to. I tried to fix it until 2AM at which point I gave up. Came back to it this morning, still baffled.
I'll be honest with you, I'm a pretty bad Javascript developer. Since starting this project Javascript has been completely new to me and I've just learn as I went along. So please forgive me if my code structure is really bad (perhaps give a couple of pointers on how to improve it?).
So, to the problem: to reproduce it, visit http://furnace.howcode.com (it's far from complete). This problem is a little confusing but I'd really appreciate the help.
So in the second column you'll see three tabs
The 'Newest' tab is selected by default. Scroll to the bottom, and 3 further results should be dynamically fetched via Ajax.
Now click on the 'Top Rated' tab. You'll see all the results, but ordered by rating
Scroll to the bottom of 'Top Rated'. You'll see SIX results returned.
This is where it goes wrong. Only a further three should be returned (there are 18 entries in total). If you're observant you'll notice two 'blocks' of 3 returned.
The first 'block' is the second page of results from the 'Newest' tab. The second block is what I just want returned.
Did that make any sense? Never mind!
So basically I checked this out in Firebug. What happens is, from a 'Clean' page (first load, nothing done) it calls ONE POST request to http://furnace.howcode.com/code/loadmore .
But every time you load a new one of the tabs, it makes an ADDITIONAL POST request each time where there should normally only be ONE.
So, can you help me? I'd really appreciate it! At this point you could start independent investigation or read on for a little further (optional) information.
Thanks!
Jack
Further Info (may be irrelevant but here for reference):
It's almost like there's some Javascript code or something being left behind that duplicates it each time. I thought it might be this code that I use to detect when the browser is scrolled to the bottom:
var col = $('#col2');
col.scroll(function(){
if (col.outerHeight() == (col.get(0).scrollHeight - col.scrollTop()))
loadMore(1);
});
So what I thought was that code was left behind, and so every time you scroll #col2 (which contains different data for each tab) it detected that and added it for #newest as well. So, I made each tab click give #col2 a dynamic class - either .newestcol, .featuredcol, or .topratedcol. And then I changed the var col=$('.newestcol');dynamically so it would only detect it individually for each tab (makin' any sense?!). But hey, that didn't do anything.
Another useful tidbit: here's the PHP for http://furnace.howcode.com/code/loadmore:
$kind = $this->input->post('kind');
if ($kind == 1){ // kind is 1 - newest
$start = $this->input->post('currentpage');
$data['query'] = "SELECT code.id AS codeid, code.title AS codetitle, code.summary AS codesummary, code.author AS codeauthor, code.rating AS rating, code.date,
code_tags.*,
tags.*,
users.firstname AS authorname,
users.id AS authorid,
GROUP_CONCAT(tags.tag SEPARATOR ', ') AS taggroup
FROM code, code_tags, tags, users
WHERE users.id = code.author AND code_tags.code_id = code.id AND tags.id = code_tags.tag_id
GROUP BY code_id
ORDER BY date DESC
LIMIT $start, 15 ";
$this->load->view('code/ajaxlist',$data);
} elseif ($kind == 2) { // kind is 2 - featured
So my jQuery code sends a variable 'kind'. If it's 1, it runs the query for Newest, etc. etc.
The PHP code for furnace.howcode.com/code/ajaxlist is:
<?php // Our query base
// SELECT * FROM code ORDER BY date DESC
$query = $this->db->query($query);
foreach($query->result() as $row) {
?>
<script type="text/javascript">
$('#title-<?php echo $row->codeid;?>').click(function() {
var form_data = {
id: <?php echo $row->codeid; ?>
};
$('#col3').fadeOut('slow', function() {
$.ajax({
url: "<?php echo site_url('code/viewajax');?>",
type: 'POST',
data: form_data,
success: function(msg) {
$('#col3').html(msg);
$('#col3').fadeIn('fast');
}
});
});
});
</script>
<div class="result">
<div class="resulttext">
<div id="title-<?php echo $row->codeid; ?>" class="title">
<?php echo anchor('#',$row->codetitle); ?>
</div>
<div class="summary">
<?php echo $row->codesummary; ?>
</div>
<!-- Now insert the 5-star rating system -->
<?php include($_SERVER['DOCUMENT_ROOT']."/fivestars/5star.php");?>
<div class="bottom">
<div class="author">
Submitted by <?php echo anchor('auth/profile/'.$row->authorid,''.$row->authorname);?>
</div>
<?php
// Now we need to take the GROUP_CONCATted tags and split them using the magic of PHP into seperate tags
$tagarray = explode(", ", $row->taggroup);
foreach ($tagarray as $tag) {
?>
<div class="tagbutton" href="#">
<span><?php echo $tag; ?></span>
</div>
<?php } ?>
</div>
</div>
</div>
<?php }
echo " ";?>
<script type="text/javascript">
var newpage = <?php echo $this->input->post('currentpage') + 15;?>;
</script>
So that's everything in PHP. The rest you should be able to view with Firebug or by viewing the Source code. I've put all the Tab/clicking/Ajaxloading bits in the tags at the very bottom. There's a comment before it all kicks off.
Thanks so much for your help!
I think you're right to suspect this code block:
var col = $('#col2');
col.scroll(function(){
if (col.outerHeight() == (col.get(0).scrollHeight - col.scrollTop()))
loadMore(1);
});
My take on this is that you keep adding additional event handlers (duplicates, essentially) each time you run this code. You need to remove (unbind) the existing event handlers with every tab click so that you can be sure that it's only firing once:
$('#col2').unbind();
var col = $('#col2');
col.scroll(function(){
if (col.outerHeight() == (col.get(0).scrollHeight - col.scrollTop()))
loadMore(1);
});
Or some such thing. See http://api.jquery.com/unbind/
$('.featurecol'); , $('.topratedcol'); and $('.newestcol'); all refer to the same column and division (<div>). As such, whenever you switch pages, you need to unbind the old scroll before rebinding the new scroll handler. (Or else you'll be appending another scroll handler and getting multiple requests sent, like now)
You can do this by adding an unbind as follows:
var col = $('.newestcol');
col.unbind('scroll');
col.scroll(function(){
if (col.outerHeight() == (col.get(0).scrollHeight - col.scrollTop()))
loadMore(1);
});
You need to do this for all of the columns as they load (code/newest, code/toprated and code/featured).
It could also be
$('#col3').fadeOut('slow', function() {
as the ajax loads there... n number of times as it fades out it calls another ajax request.
not saying its the defenet answer but something looking into...