www.webdeveloper.com
Recent Articles
  • Finding Slow Running Queries in ASE 15
  • A More Advanced Pie Chart for Analysis Services Data
  • Adobe AIR Programming Unleashed: Working with Windows
  • Performance Testing SQL Server 2008's Change Data Capture Functionality
  • The ABC's of PHP: Introduction to PHP
  • How to Migrate from BasicFiles to SecureFiles Storage
  • Why the Twitter Haters Are Wrong
  • User Personalization with PHP: Beginning the Application
  • Whats in an Oracle Schema?
  • Lighting Enhancement in Photoshop
  •  

    Go Back   WebDeveloper.com > Server-Side Development > PHP

    PHP Discussion and technical support for using and deploying PHP based websites.

    Reply
     
    Thread Tools Search this Thread Rate Thread Display Modes
      #1  
    Old 05-15-2003, 03:51 PM
    jrlamar's Avatar
    jrlamar jrlamar is offline
    Registered User
     
    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
    Reply With Quote
      #2  
    Old 05-15-2003, 04:10 PM
    pyro's Avatar
    pyro pyro is offline
    Registered User
     
    Join Date: Dec 2002
    Location: High on life
    Posts: 10,183
    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!
    Reply With Quote
      #3  
    Old 05-15-2003, 05:30 PM
    jrlamar's Avatar
    jrlamar jrlamar is offline
    Registered User
     
    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
    Reply With Quote
      #4  
    Old 05-15-2003, 05:38 PM
    pyro's Avatar
    pyro pyro is offline
    Registered User
     
    Join Date: Dec 2002
    Location: High on life
    Posts: 10,183
    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!
    Reply With Quote
      #5  
    Old 05-19-2003, 04:37 PM
    jrlamar's Avatar
    jrlamar jrlamar is offline
    Registered User
     
    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
    Reply With Quote
      #6  
    Old 05-19-2003, 05:25 PM
    pyro's Avatar
    pyro pyro is offline
    Registered User
     
    Join Date: Dec 2002
    Location: High on life
    Posts: 10,183
    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!
    Reply With Quote
      #7  
    Old 05-19-2003, 05:36 PM
    jrlamar's Avatar
    jrlamar jrlamar is offline
    Registered User
     
    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
    Reply With Quote
      #8  
    Old 05-19-2003, 06:20 PM
    pyro's Avatar
    pyro pyro is offline
    Registered User
     
    Join Date: Dec 2002
    Location: High on life
    Posts: 10,183
    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!
    Reply With Quote
      #9  
    Old 05-19-2003, 06:30 PM
    jrlamar's Avatar
    jrlamar jrlamar is offline
    Registered User
     
    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
    Reply With Quote
      #10  
    Old 05-19-2003, 06:40 PM
    pyro's Avatar
    pyro pyro is offline
    Registered User
     
    Join Date: Dec 2002
    Location: High on life
    Posts: 10,183
    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!
    Reply With Quote
      #11  
    Old 05-19-2003, 06:53 PM
    jrlamar's Avatar
    jrlamar jrlamar is offline
    Registered User
     
    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
    Reply With Quote
      #12  
    Old 05-19-2003, 10:40 PM
    pyro's Avatar
    pyro pyro is offline
    Registered User
     
    Join Date: Dec 2002
    Location: High on life
    Posts: 10,183
    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!
    Reply With Quote
      #13  
    Old 05-20-2003, 09:13 AM
    jrlamar's Avatar
    jrlamar jrlamar is offline
    Registered User
     
    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
    Reply With Quote
      #14  
    Old 05-20-2003, 11:30 AM
    pyro's Avatar
    pyro pyro is offline
    Registered User
     
    Join Date: Dec 2002
    Location: High on life
    Posts: 10,183
    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!
    Reply With Quote
    Reply

    Bookmarks


    Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
     
    Thread Tools Search this Thread
    Search this Thread:

    Advanced Search
    Display Modes Rate This Thread
    Rate This Thread:

    Posting Rules
    You may not post new threads
    You may not post replies
    You may not post attachments
    You may not edit your posts

    BB code is On
    Smilies are On
    [IMG] code is Off
    HTML code is Off
    Forum Jump


    All times are GMT -5. The time now is 12:50 AM.



    Acceptable Use Policy

    internet.comMediabistrojusttechjobs.comGraphics.com

    WebMediaBrands Corporate Info


    Advertise | Newsletters | Feedback | Submit News

    Legal Notices | Licensing | Permissions | Privacy Policy

    Powered by vBulletin® Version 3.7.3
    Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.