Forum Moderators: coopster
My content page is composed of PHP variables containg meta information, tool tip text, titles, etc., which is inserted all throughout my template when the script is parsed.
I have links embedded in the content (a really big variable including HTML) which I would like to use to open a pop-up form for things like subscribing to a newsletter. This is a cute little DHTML Window script from Dynamic Drive (http://www.dynamicdrive.com) that uses a hidden iframe and can be resized and moved around on the screen.
What happens is that if I embed the link in the template body, it works fine, but if I embed it in the content called as a variable, it doesn't react. I am thinking it may have something to do with the fact that I change all double quotes to single quotes when I am including quotes in the variable (the content).
Can someone give me some advice from the sketchy information I have provded?
Many thanks,
Calvin
There are two PHP files, the wrapper or template which contain HTML written with double quotes as normal where required, single quotes where required. The Javascript function named in the first post is included in the <head> section of this file/document. In this file/document, near the end of the body, is the following call:
<a href="javascript:loadwindow('http://www.google.com',600,400)">Click for Google</a></body>
In another PHP file named Main, I have a variable called $varContent, which contains the call written as:
<? $varContent = "<a onClick='javascript:loadwindow('http://myDomain.com/cgi-bin/y/d.cgi?form',300,400);' style='cursor:hand'>Click Here</a>";?>
Main is pulled into the template with this include
<? include '/var/www/html/php/Main.php';?>
and then the variable is placed in the middle of the body of the template using:
<? echo ${varContent};?>
and winds up as:
<a onClick='javascript:loadwindow('http://myDomain.com/cgi-bin/y/d.cgi?form',300,400);' style='cursor:hand'>
Click Here</a>
I've left a bunch of other stuff out. I hope this is sufficient.
Thanks.
Escape the double quotes you need to send to the browser, like this:
<? $varContent = "<a onClick=\"javascript:loadwindow('http://myDomain.com/cgi-bin/y/d.cgi?form',300,400);\" style=\"cursor:hand\">Click Here</a>";
Timster got it. It was the need for escaping the double quote when pulling them through PHP.
This morning I started thinking that maybe what I should do is change the variable to where it is the name of a text or htm file that I can call with the include statement when the variable is populated.
I'm thinking that this way I could leave all the content formatted with the html and not need to worry about this fine a detail.
Your opinions?
CM
<? $varContent = "<a onClick=\"javascript:loadwindow('http://myDomain.com/cgi-bin/y/d.cgi?form',300,400);\" style=\"cursor:hand\">Click Here</a>";
needs a variable appended to the "form" as in <? $varContent = "<a onClick=\"javascript:loadwindow('http://myDomain.com/cgi-bin/y/d.cgi?form-VARIABLE',300,400);\" style=\"cursor:hand\">Click Here</a>";
I have the following variable available - $_SESSION['VarNum']
Any help is appreciated.
<a onClick = "javascript:loadwindow(
'http://myDomain.com/cgi-bin/y/d.cgi?form=<?php
echo $_SESSION['VarNum']?>',300,400);" style="cursor:hand">Click Here</a>"; Since you're a self-described greenhorn, here's a little Web Apps 101:
When you're working on a page like this, bear in mind you're effectively writing two "programs" like so:
1) The server side PHP code executes first on the web server.
2) The client-side code (HTML and JavaScript) interpreted by your computer's browser.
With a page like the one you're writing the PHP code is effectively writing some of your JavaScript and HTML code.
I hope that's some help.
It was close enough I was able to figure it out. First thing that happend was that the entire contents between the PHP begin and end tags was being sent to the cgi script. The letters PHP and the letters echo were sent along separated by something like the %20 code. Also, I had to change the $_SESSION['VarNum'] to $VarNum in order to get the variable.
I don't think $VarNum was set anywhere in the template. And I seem to remember seeing it mentioned somewhere when I was reading about using session variables.
Howsomever, you guidance prompted me to the correct answer. I thought I had tried something like that, but on reflection, think that maybe I was trying to insert quote marks and escape slashes where they weren't needed because when the PHP is parsed, the javascript is ignored.
Regarding the PHP being parsed and building both the html and javascript, thanks for the reminder. I got that part. What I keep running into is trying to remember if a part of my template has been parsed and included or not. I think I have three layers when a page is built, and some of the includes get me frustrated.
Anyhoo, many thanks again.