0

How can I pass Variables from a form submit into FPDF.

I have Something like this

 <form method="post" action="pdf_page.php">
<input id="name" type="text" size="20" />
<button type="submit" class="btn btn-primary" id="btn_next">Submit</button>
</form>

and this is my pdf_page.php

<?php
$name=$_POST['name'];
require('fpdf/fpdf.php');                             
$pdf= new FPDF('P','mm','A4');
$pdf->AddPage();
$pdf->SetFont('Arial','','9');
$pdf->Cell('80','4',$name,'0','1','');  ////i want to show the variable here
$pdf->Output();
?>

when I hit the Submit button, I get these errors

  • Undefined index: name in C:........

  • Fatal error: Uncaught exception 'Exception' with message 'FPDF error: Some data has already been output, can't send PDF file' in C:\wamp64\www\Form\fpdf\fpdf.php on line 271

  • Exception: FPDF error: Some data has already been output, can't send PDF file in C:\wamp64\www\Form\fpdf\fpdf.php on line 271

What am I doing Wrong?? I don't need to store the variables in Mysql I just want to pass them into the pdf file..... Can anybody Help me ?

1 Answers1

0

In the html form, you need to add a name attribute to the input. That is what is contained in the post array

<input id="name" name="name" type="text" size="20" />

Php's global post array, $_POST is a key value association. The key is the name attribute from the html form, while the value is the value of the key.

Do a simple dump of the post array as

var_dump($_POST); //this shows you what is contained.this is just for debugging purposes
Rotimi
  • 4,783
  • 4
  • 18
  • 27