print div content on another page

1

I have a php page that receives values from a form (post) and wanted to print those results on paper.

It turns out that by clicking the button the value in textarea does not appear in the printout.

On the source page I have this form with textarea and a button to print, like this:

<form method="post">
<p><textarea name="textoImprimir" cols="" rows="" class="anamnese-tarea">quero imprimir este texto que acabei de digitar.</textarea></p>
<p><iframe src="imprimir.php" name="frame1" style="display:none;"></iframe>
   <input type="button" onclick="frames['frame1'].print()" value="print!"></p>
</form>

On the print.php page I have this:

<?php
$textoImprimir = $_POST['textoImprimir'];
?>    
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Imprimir</title>
<style>
html, body { width:100%; height:100%; margin:0px; }
.fundo { background: url(../_imagens/fundo_print.png);
    background-size: 100% 100%;
    background-repeat: no-repeat;
}
@page {
  size: A4;
  margin: 15mm 15mm 15mm 15mm;
}

table { top:18%; bottom:20%; position:absolute; }
</style>
</head>
<body class="fundo">
<table width="100%" height="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td height="20%" align="center" valign="middle">ALGUM TEXTO</td>
  </tr>
  <tr>
    <td height="80%" align="justify" valign="top"><?php echo $imprimir;?></td>
  </tr>
</table>
</body>
</html>
    
asked by anonymous 03.11.2017 / 21:25

1 answer

2

Change the print form to be this way, so we will pass via POST so that we can print to the print.php file

<form method="post" action="imprimir.php" enctype="multipart-form/data">
    <textarea name="textoImprimir" id="textoImprimir" cols="" rows="" class="anamnese-tarea">quero imprimir este texto que acabei de digitar.</textarea>
    <input type="submit" value="Imprimir!">
</form>

Inside the print.php you poe

<script>window.print();</script>

And switch

$textoImprimir = $_POST['textoImprimir'];

by

$imprimir = $_POST['textoImprimir'];
    
03.11.2017 / 21:36