madshadow
06-10-2006, 07:24 PM
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...
chump2877
06-10-2006, 08:46 PM
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:
<a href="javascript: submitForm('window.document.form1','thisForm');">Printer friendly version</a>
the hidden form:
<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:
<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...
madshadow
06-11-2006, 05:56 AM
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!
chump2877
06-11-2006, 11:27 AM
Sorry I had a pair of quotes where they shouldn;t be...here is an example usage that I tested:
whatever1.php
<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
<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
madshadow
06-13-2006, 04:32 AM
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!
chump2877
06-13-2006, 09:09 PM
you're welcome, glad i could help :thumbsup: