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.

1

1 Answer 1

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>"
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for your fast reply, What about if I can't use global variable or the $text1 was very long text?
He actually probably needs a mix of the two. Probably will want to add teh full URL with query string to both the window.open() parameter as well as the href property of the <a> (for case where javascript is not enabled. You also need to urlencode() the value. I will edit answer for you...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.