0

I have a PHP page index.php contains javascript window.open code to make another page create_pdf.php popup and pass some PHP variables to it to create a pdf file using FPDF

Here is my variables:

$text1 = "this is text1";
$text2 = "this is text2";

And here is FPDF code in the http://mysite.com/create_pdf.php page, which I need to pass PHP variables $text1 and $text2 to it from index.php page:

require('fpdf.php');
$pdf = new FPDF();
$pdf->AddPage();
$pdf->SetFont('Arial','B',16);
$pdf->Cell(40, 10, $text1);
$pdf->ln();
$pdf->Cell(40,10, $text2);
$pdf->Output();

And here is the PHP variable $pdf_link which contains javascript window.open code:

$pdf_link = "<div class=\"pdf-box\"><a target=\"_blank\"  
onclick=\"return !window.open(this.href, 'pdf', 'width=640,height=300')\" 
href=\"http://mysite.com/create_pdf.php\"; 
return false;\">Create pdf</a></div>";

Exactly what I need is how can I edit the variable $pdf_link in index.php so I can Pass $text1 and $text2 or any number of variables to create_pdf.php page.

Note: I'm familiar with PHP but not familiar with Javascript.

usama sulaiman
  • 2,013
  • 4
  • 24
  • 37
  • Just thought I should link my "duplicate post", the question is the same, but much simpler context IMO. http://stackoverflow.com/questions/42498574/php-pass-variable-to-new-window-open-javascript/42498745#42498745 – FreeSoftwareServers Feb 28 '17 at 02:45

1 Answers1

1

Not sure I am following but you might want to try:

$pdf_link = "<div class=\"pdf-box\"><a target=\"_blank\"  
onclick=\"return !window.open(this.href, 'pdf', 'width=640,height=300')\" 
href=\"http://mysite.com/create_pdf.php?text1=" . urlencode($text1)  .  "&text2=" . urlencode($text2)  .  "\"; 
return false;\">Create pdf</a></div>";

or

$fullLinkWithParams = urlencode("http://mysite.com/create_pdf.php?text1=" . $text1  .  "&text2=" . $text2);

$pdf_link = "<div class=\"pdf-box\"><a target=\"_blank\"  
onclick=\"return !window.open('" . $fullLinkWithParams  .  "', 'pdf', 'width=640,height=300')\">Create pdf</a></div>"
Mike Brant
  • 70,514
  • 10
  • 99
  • 103
tibc-dev
  • 973
  • 11
  • 16