Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New Coder
    Join Date
    May 2006
    Posts
    47
    Thanks
    0
    Thanked 0 Times in 0 Posts

    duplicating content in new window

    hello all,

    i know you can us CSS to make a "printer-friendly" version of a page, but is there a way to do it with php. i want to make a link that, when clicked, opens a new page with all the content that was just generated by the script in that first page.

    i suppose i could maybe just duplicate the page and pass variables along with a GET url... is there a way to attach a "post" action to a regular hyperlink? or is there an easier way to do it?

    thanks for the help...

  • #2
    Senior Coder chump2877's Avatar
    Join Date
    Dec 2004
    Location
    the U.S. of freakin' A.
    Posts
    2,746
    Thanks
    18
    Thanked 155 Times in 146 Posts
    is there a way to attach a "post" action to a regular hyperlink?
    FYI, You can use a javascript link that submits a dynamically populated hidden form on your page to do this....for example, the link:
    Code:
    <a href="javascript: submitForm('window.document.form1','thisForm');">Printer friendly version</a>
    the hidden form:

    PHP Code:
    <form name="form1" target="thisForm" action="printerFriendlyFile.php" method="post">
        <input type="hidden" name="variable1" value="<? echo $value1?>" />
        <input type="hidden" name="variable2" value="<? echo $value2?>" />
        <input type="hidden" name="variable3" value="<? echo $value3?>" />
        <input type="hidden" name="variable4" value="<? echo $value4?>" />
        <input type="hidden" name="variable5" value="<? echo $value5?>" />
        <input type="hidden" name="variable6" value="<? echo $value6?>" />
    </form>
    the javascript:

    Code:
    <script type="text/javascript">
    <!--
    
    function submitForm(form_object,theTarget)
    {
    	newWindow = window.open(form_object.action, theTarget, "width=800,height=600,resizable=yes,scrollbars=yes");
    	newWindow.focus();
    	form_object.submit();	
    }
    
    -->
    </script>
    If I did this right (didn;t actually test it), printerFriendlyFile.php will open in a new window, process the form, and then its up to you to format the POST variables from there and display your printer-firendly content...
    Last edited by chump2877; 06-10-2006 at 08:57 PM.
    Regards, R.J.

    ---------------------------------------------------------

    Help spread the word! Like my YouTube-to-Mp3 Conversion Script on Facebook !! :)
    [Related videos and tutorials are also available at my YouTube channel and on Dailymotion]
    Get free updates about new software version releases, features, and bug fixes!

  • #3
    New Coder
    Join Date
    May 2006
    Posts
    47
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by chump2877
    If I did this right (didn;t actually test it), printerFriendlyFile.php will open in a new window, process the form, and then its up to you to format the POST variables from there and display your printer-firendly content...

    chump,

    It doesn't seem to be working for me. when i click the link the resulting page is blank. maybe i'm placing the different parts of the code in the wrong place but i think i have it right. are you able to get it to work?

    thanks for your continued help!

  • #4
    Senior Coder chump2877's Avatar
    Join Date
    Dec 2004
    Location
    the U.S. of freakin' A.
    Posts
    2,746
    Thanks
    18
    Thanked 155 Times in 146 Posts
    Sorry I had a pair of quotes where they shouldn;t be...here is an example usage that I tested:

    whatever1.php

    PHP Code:
    <HTML>
    <HEAD>
    <TITLE></TITLE>

    <script type="text/javascript">
    <!--

    function submitForm(form_object,theTarget)
    {
        newWindow = window.open(form_object.action, theTarget, "width=800,height=600,resizable=yes,scrollbars=yes");
        newWindow.focus();
        form_object.submit();
    }

    -->
    </script>

    </HEAD>

    <BODY>

    <?

    $value_array 
    = array('value1','value2','value3','value4','value5','value6');


    foreach (
    $value_array as $val)
    {
        echo 
    $val "<br>";
    }

    ?>

    <br><a href="javascript: submitForm(window.document.form1,'thisForm');">Printer friendly version</a>


    <form name="form1" target="thisForm" action="printerFriendlyFile.php" method="post">

    <?

    foreach ($value_array as $key => $val)
    {
       print 
    '<input type="hidden" name="variable'.$key.'" value="'.$val.'" />';
    }

    ?>

    </form>


    </BODY>
    </HTML>
    printerFriendlyFile.php

    PHP Code:
    <HTML>
    <HEAD>
    <TITLE></TITLE>
    </HEAD>

    <BODY>


    <?

    foreach ($_POST as $val)
    {
        echo 
    $val "<br>";
    }

    ?>


    </BODY>
    </HTML>
    format printerFriendlyFile.php however you want...I left up my test demo so you can see that the code works, here: http://www.mediamogulsweb.com/client/whatever1.php
    Regards, R.J.

    ---------------------------------------------------------

    Help spread the word! Like my YouTube-to-Mp3 Conversion Script on Facebook !! :)
    [Related videos and tutorials are also available at my YouTube channel and on Dailymotion]
    Get free updates about new software version releases, features, and bug fixes!

  • #5
    New Coder
    Join Date
    May 2006
    Posts
    47
    Thanks
    0
    Thanked 0 Times in 0 Posts
    chump,

    thanks a lot...i tested your code and it works great. i'm working on integrating it into my system.

    again, thanks for your help!

  • #6
    Senior Coder chump2877's Avatar
    Join Date
    Dec 2004
    Location
    the U.S. of freakin' A.
    Posts
    2,746
    Thanks
    18
    Thanked 155 Times in 146 Posts
    you're welcome, glad i could help
    Regards, R.J.

    ---------------------------------------------------------

    Help spread the word! Like my YouTube-to-Mp3 Conversion Script on Facebook !! :)
    [Related videos and tutorials are also available at my YouTube channel and on Dailymotion]
    Get free updates about new software version releases, features, and bug fixes!


  •  

    Posting Permissions

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