Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 30th, 2012  |  syntax: None  |  size: 2.42 KB  |  hits: 27  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. How to use html form data for fpdf form creation
  2. <!DOCTYPE html>
  3.   <html>
  4.   <head>
  5.  <?php
  6.  $intro = mysql_real_escape_string($_POST['intro']);
  7.  $hostname ="localhost";
  8.  $db_user = "someuser";
  9.  $db_password = "somepassword";
  10.  $database = "form_something";
  11.  $db_table = "FORM";
  12.  $db = mysql_connect ($hostname, $db_user, $db_password);
  13.  mysql_select_db($database,$db);
  14.  ?>
  15.   <title><h2>this is my form</h2><title>
  16.   <?php
  17.   if (isset($_REQUEST['Submit'])) {
  18.   # THIS CODE TELLS MYSQL TO INSERT THE DATA FROM THE FORM INTO MY MYSQL TABLE
  19.   $sql = "INSERT INTO $db_table(information) values ('".mysql_real_escape_string(stripslashes($_REQUEST['information']))."')";
  20.   if($result = mysql_query($sql ,$db)) {
  21.   echo <h1>Thank you</h1>information has been entered into our database<br><img   src="http://someimage.com/here/is/the/image.jpg"';
  22.  {
  23.  p
  24.  } else
  25.  {
  26.  echo "ERROR: ".mysql_error();
  27.  }
  28.  } else
  29.  {
  30.  ?>
  31.   ?>
  32.   </head>
  33.   <form action="pdf.php">
  34.   <td colspan="2">type your information here<input type="text" name="information">
  35.   <input type="submit" name="Submit" value="Submit">
  36.   </body>
  37.   </form>
  38.   </html>
  39.        
  40. <?php
  41. require('fpdf.php');
  42.  
  43. class PDF extends FPDF
  44.  {
  45.  // Page header
  46. function Header()
  47. {
  48. // Logo
  49. $this->Image('logo.png',140,6,60);
  50. // Arial bold 15
  51. $this->SetFont('Arial','B',15);
  52. // Move to the right
  53. $this->Cell(60);
  54.  // Title
  55. $this->Cell(80,10,' Form',1,0,'C');
  56. // Line break
  57. $this->Ln(20);
  58. }
  59.  
  60. function Footer()
  61. {
  62. // Position at 1.5 cm from bottom
  63. $this->SetY(-15);
  64. // Arial italic 8
  65. $this->SetFont('Arial','I',8);
  66. // Page number
  67. $this->Cell(0,10,'Page '.$this->PageNo().'/{nb}',0,0,'C');
  68. }
  69. }
  70.  
  71. $pdf = new PDF();
  72. $pdf->AliasNbPages();
  73. $pdf->AddPage();
  74. $pdf->SetFont('Times','',12);
  75. for($i=1;$i<=40;$i++)
  76. $pdf->Cell(0,10,'Printing line number '.$i,0,1);
  77. $pdf->Output();
  78. ?>
  79.        
  80. <form action="to_pdf.php" method="POST">
  81.     <p>Name</p>
  82.     <input type="text" name="name">">
  83.  
  84.     <p>Priority</p>
  85.     <select name="priority" size="1">
  86.         <option value="Low">Low</option>
  87.         <option value="Normal">Normal</option>
  88.         <option value="High">High</option>
  89.         <option value="Emergency">Emergency</option>
  90.     </select>
  91.  
  92.     <input type="submit" value="Send"><input type="reset" value="Clear">
  93. </form>
  94.        
  95. <?php
  96.  
  97. $name = $_POST['name'];
  98. $priority = $_POST['priority'];
  99.  
  100. require('fpdf.php');
  101.  
  102. $pdf = new FPDF();
  103. $pdf->AddPage();
  104.  
  105. $pdf->SetFont('Arial','B',16);
  106.  
  107. $pdf->MultiCell(40,10,$name);
  108. $pdf->MultiCell(40,10,$priority);
  109.  
  110. $pdf->Output();
  111.  
  112. ?>