- How to use html form data for fpdf form creation
- <!DOCTYPE html>
- <html>
- <head>
- <?php
- $intro = mysql_real_escape_string($_POST['intro']);
- $hostname ="localhost";
- $db_user = "someuser";
- $db_password = "somepassword";
- $database = "form_something";
- $db_table = "FORM";
- $db = mysql_connect ($hostname, $db_user, $db_password);
- mysql_select_db($database,$db);
- ?>
- <title><h2>this is my form</h2><title>
- <?php
- if (isset($_REQUEST['Submit'])) {
- # THIS CODE TELLS MYSQL TO INSERT THE DATA FROM THE FORM INTO MY MYSQL TABLE
- $sql = "INSERT INTO $db_table(information) values ('".mysql_real_escape_string(stripslashes($_REQUEST['information']))."')";
- if($result = mysql_query($sql ,$db)) {
- echo <h1>Thank you</h1>information has been entered into our database<br><img src="http://someimage.com/here/is/the/image.jpg"';
- {
- p
- } else
- {
- echo "ERROR: ".mysql_error();
- }
- } else
- {
- ?>
- ?>
- </head>
- <form action="pdf.php">
- <td colspan="2">type your information here<input type="text" name="information">
- <input type="submit" name="Submit" value="Submit">
- </body>
- </form>
- </html>
- <?php
- require('fpdf.php');
- class PDF extends FPDF
- {
- // Page header
- function Header()
- {
- // Logo
- $this->Image('logo.png',140,6,60);
- // Arial bold 15
- $this->SetFont('Arial','B',15);
- // Move to the right
- $this->Cell(60);
- // Title
- $this->Cell(80,10,' Form',1,0,'C');
- // Line break
- $this->Ln(20);
- }
- function Footer()
- {
- // Position at 1.5 cm from bottom
- $this->SetY(-15);
- // Arial italic 8
- $this->SetFont('Arial','I',8);
- // Page number
- $this->Cell(0,10,'Page '.$this->PageNo().'/{nb}',0,0,'C');
- }
- }
- $pdf = new PDF();
- $pdf->AliasNbPages();
- $pdf->AddPage();
- $pdf->SetFont('Times','',12);
- for($i=1;$i<=40;$i++)
- $pdf->Cell(0,10,'Printing line number '.$i,0,1);
- $pdf->Output();
- ?>
- <form action="to_pdf.php" method="POST">
- <p>Name</p>
- <input type="text" name="name">">
- <p>Priority</p>
- <select name="priority" size="1">
- <option value="Low">Low</option>
- <option value="Normal">Normal</option>
- <option value="High">High</option>
- <option value="Emergency">Emergency</option>
- </select>
- <input type="submit" value="Send"><input type="reset" value="Clear">
- </form>
- <?php
- $name = $_POST['name'];
- $priority = $_POST['priority'];
- require('fpdf.php');
- $pdf = new FPDF();
- $pdf->AddPage();
- $pdf->SetFont('Arial','B',16);
- $pdf->MultiCell(40,10,$name);
- $pdf->MultiCell(40,10,$priority);
- $pdf->Output();
- ?>