Click to See Complete Forum and Search --> : Creating a complex pop-up window ...
jrlamar
05-15-2003, 02:51 PM
(for Pyro's benefit ... ha, ha)
OK, here's the situation ...
From a static HTML page, I'm calling a Perl script from a pop-up window (via JavaScript) that I've customized to provide an "e-mailable version" of the static HTML content from the parent window. The trick is that the pop-up window -- which contains a simple form -- has to have information that varies from page to page (specifically, the URL, the title, and the root server path to the parent HTML page). Previously, I've hand-coded each pop-up window individually ... which is a major pain in the neck, of course.
So my question is: How can I create a generic pop-up window that automatically and dynamically pulls in the necessary information from the parent HTML window -- that is, the information inside the <title> tags as well as the document name (example.html) -- which I can then drop into the form tags in this pop-up window? In other words, I want to pass parent window variables into the pop-up window HTML code like this ...
<example form>
<input type=HIDDEN name="pagetosend" value="/root/path/to/parent_example.html">
<input type=HIDDEN name="pagename" value="Example Parent Page Title">
<input type=HIDDEN name="pageurl" value="http://www.123.com/parent_example.html">
</form>
Note: Users need to be able to fill out certain other form fields (recipient's name, e-mail address, etc.) themselves from this pop-up window, too.
What's the best way (or ANY way) to accomplish this? Help!
Thanks,
Jason
Try this... you have to use javascript, but the rest is done in PHP.
<?PHP
$rootpath = $_SERVER['PATH_TRANSLATED'];
$host = $_SERVER['HTTP_HOST'];
$hostname = "http://".$host.$_SERVER['SCRIPT_NAME'];
?>
<html>
<head>
<title>My Page</title>
<script language="javascript" type="text/javascript">
function getTitle() {
document.myform.pagename.value = document.title;
}
</script>
</head>
<body onload="getTitle();">
<form name="myform">
<input type="hidden" name="pagetosend" value="<? echo "$rootpath"; ?>">
<input type="hidden" name="pagename" value="Default">
<input type="hidden" name="pageurl" value="<? echo "$hostname"; ?>">
</form>
</body>
</html>
jrlamar
05-15-2003, 04:30 PM
pyro,
I keep getting this message in the pop-up window:
"Parse error: parse error, unexpected T_VARIABLE in /path/to/my/page/test.php on line 3"
???
Jason
Put a phpinfo script on your server and let me see a link to it:
<?PHP
phpinfo ();
?>
Or, it might work to fix the problem to switch this line:
$rootpath = $_SERVER['PATH_TRANSLATED'];
to:
$rootpath = $_SERVER['SCRIPT_FILENAME'];
jrlamar
05-19-2003, 03:37 PM
pyro,
Still getting the error, even after the $rootpath fix. It looks to be the $host line that's causing the problem (assuming the line numbering is accurate). Anyway, here's the PHP info page link you requested ...
http://web.owu.edu/php_test.php
Thanks for your help,
Jason
Well, if you don't have PATH_TRANSLATED or SCRIPT_FILENAME, you could try this to return it:
$rootpath = $_SERVER['DOCUMENT_ROOT'].$_SERVER['PHP_SELF'];
jrlamar
05-19-2003, 04:36 PM
pyro,
No, I think the SCRIPT_FILENAME version of $rootpath is working. Here's what I currently have at the top of my Web page ...
<?php
$rootpath = $_SERVER['SCRIPT_FILENAME'];
$host_=_$_SERVER['HTTP_HOST'];
$hostname_=_"http://".$host.$_SERVER["SCRIPT_NAME"];
?>
And the error I'm getting is ...
Parse error: parse error, unexpected T_VARIABLE in /path/to/test.php on line 3
So, depending on how PHP does line counting, it's either the $host or the $hostname that's causing the problem. Does PHP count <?php as line 1?
Jason
All the variables you are using are fine, according to the phpinfo() script you linked to. Did you just copy it out of these forums? If so, that might be the problem. Try typing it in, rather than copying and pasting...
jrlamar
05-19-2003, 05:30 PM
pyro,
Ah ha ... didn't think of that. Well, it made it further now before it had an error. The new obstacle is:
Parse error: parse error, unexpected '\"' in /path/to/test.php on line 26
Using the Line Number feature in my text editor, I see line 26 is:
<input type=HIDDEN name="pagetosend" value="<?_echo_"$rootpath";_?>">
I've already tried this with all the $rootpath variations you've posted so far, and they're all getting the same backslash error.
Jason
Try deleting that line and re-typing, as well...
jrlamar
05-19-2003, 05:53 PM
Yes! That did it! Although the PHP is executing properly now, I have new problems: All the hidden variables are referencing the pop-up window itself ... rather than the parent window. Thus ...
<input type=HIDDEN name="pagetosend" value="/var/www/htdocs/test.php">
<input type=HIDDEN name="pagename" value="Default">
<input type=HIDDEN name="pageurl" value="http://web.owu.edu/test.php">
Hmmm ... now what?
Jason
Oh... that makes it entirely different ballgame. You are not going to have to submit the values to your popup using a query string (yourpopup.php?firstval&secondval&thirdval) and then parse this off on the popup page using the $_SERVER['QUERY_STRING'] command...
jrlamar
05-20-2003, 08:13 AM
Please don't tell me that I have to set those values (from the parent window) manually. If so, I'm right back to where I started from. The whole point of this, as I explained at the beginning of the thread, was that I wanted to have an "automated" pop-up window that pulled in attributes from whatever parent window opened it.
Or am I misundertanding what you're saying?
Jason
Nope, you don't have to set them manually, as I said, you will just send the values from your parent window to the popup window via the query string. You do that like this:
This code goes in your parent pages
<?PHP
$rootpath = $_SERVER['SCRIPT_FILENAME'];
$host = $_SERVER['HTTP_HOST'];
$hostname = "http://".$host.$_SERVER["SCRIPT_NAME"];
$contents = @file($rootpath);
foreach ($contents as $line_num => $line) {
if (preg_match('/\<title\>(.*)\<\/title\>/i', $line, $a)) {
$title = $a[1];
}
}
$query = "rootpath=".$rootpath."&host=".$host."&hostname=".$hostname."&title=".$title;
?>
<html>
<head>
<title>Parent Page</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script language="javascript" type="text/javascript">
function openPopup(url) {
window.open(url);
}
</script>
</head>
<body>
<a href="popup.php?<?PHP echo $query; ?>" onclick="openPopup(this.href); return false;">Open popup</a>
</body>
</html>
This is the code for popup.php
<html>
<head>
<title>Popup Page</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<form name="myform">
Rootpath: <input type="text" name="rootpath" value="<?PHP echo $_GET['rootpath']; ?>"/><br/>
Host: <input type="text" name="host" value="<?PHP echo $_GET['host']; ?>"/><br/>
Hostname: <input type="text" name="hostname" value="<?PHP echo $_GET['hostname']; ?>"/><br/>
Title: <input type="text" name="title" value="<?PHP echo $_GET['title']; ?>"/><br/>
</form>
</body>
</html>