www.webdeveloper.com
Results 1 to 14 of 14

Thread: Creating a complex pop-up window ...

  1. #1
    Join Date
    May 2003
    Location
    Central Ohio, U.S.
    Posts
    26

    Creating a complex pop-up window ...

    (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

  2. #2
    Join Date
    Dec 2002
    Location
    High on life
    Posts
    10,104
    Try this... you have to use javascript, but the rest is done in PHP.

    PHP Code:
    <?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>

    Personal website http://www.ryanbrill.com/
    Business website: http://www.infinitywebdesign.com/
    TypeSpace http://www.typespace.org/

    I reject your reality and substitute it with my own!

  3. #3
    Join Date
    May 2003
    Location
    Central Ohio, U.S.
    Posts
    26
    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

  4. #4
    Join Date
    Dec 2002
    Location
    High on life
    Posts
    10,104
    Put a phpinfo script on your server and let me see a link to it:

    PHP Code:
    <?PHP
    phpinfo 
    ();
    ?>
    Or, it might work to fix the problem to switch this line:

    $rootpath = $_SERVER['PATH_TRANSLATED'];
    to:
    $rootpath = $_SERVER['SCRIPT_FILENAME'];

    Personal website http://www.ryanbrill.com/
    Business website: http://www.infinitywebdesign.com/
    TypeSpace http://www.typespace.org/

    I reject your reality and substitute it with my own!

  5. #5
    Join Date
    May 2003
    Location
    Central Ohio, U.S.
    Posts
    26
    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

  6. #6
    Join Date
    Dec 2002
    Location
    High on life
    Posts
    10,104
    Well, if you don't have PATH_TRANSLATED or SCRIPT_FILENAME, you could try this to return it:

    PHP Code:
    $rootpath $_SERVER['DOCUMENT_ROOT'].$_SERVER['PHP_SELF']; 

    Personal website http://www.ryanbrill.com/
    Business website: http://www.infinitywebdesign.com/
    TypeSpace http://www.typespace.org/

    I reject your reality and substitute it with my own!

  7. #7
    Join Date
    May 2003
    Location
    Central Ohio, U.S.
    Posts
    26
    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

  8. #8
    Join Date
    Dec 2002
    Location
    High on life
    Posts
    10,104
    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...

    Personal website http://www.ryanbrill.com/
    Business website: http://www.infinitywebdesign.com/
    TypeSpace http://www.typespace.org/

    I reject your reality and substitute it with my own!

  9. #9
    Join Date
    May 2003
    Location
    Central Ohio, U.S.
    Posts
    26
    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

  10. #10
    Join Date
    Dec 2002
    Location
    High on life
    Posts
    10,104
    Try deleting that line and re-typing, as well...

    Personal website http://www.ryanbrill.com/
    Business website: http://www.infinitywebdesign.com/
    TypeSpace http://www.typespace.org/

    I reject your reality and substitute it with my own!

  11. #11
    Join Date
    May 2003
    Location
    Central Ohio, U.S.
    Posts
    26
    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 ...

    Code:
    <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

  12. #12
    Join Date
    Dec 2002
    Location
    High on life
    Posts
    10,104
    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...

    Personal website http://www.ryanbrill.com/
    Business website: http://www.infinitywebdesign.com/
    TypeSpace http://www.typespace.org/

    I reject your reality and substitute it with my own!

  13. #13
    Join Date
    May 2003
    Location
    Central Ohio, U.S.
    Posts
    26
    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

  14. #14
    Join Date
    Dec 2002
    Location
    High on life
    Posts
    10,104
    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
    Code:
    <?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
    Code:
    <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>

    Personal website http://www.ryanbrill.com/
    Business website: http://www.infinitywebdesign.com/
    TypeSpace http://www.typespace.org/

    I reject your reality and substitute it with my own!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles