Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => General

PHP to PDF probems

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

PHP to PDF probems

Postby zenko44 » Fri Apr 12, 2013 9:05 am

Hi Guys, I have built a for that outputs to pdf, now i have multiple textareas in this form but it only exports the last field.
the code is
Code: Select all
<?php
  if(isset($_POST['submit']))
  {
    $name = $_POST['name'];
    $content1 = $_POST['content1'];
    $content2 = $_POST['content2'];
    $content3 = $_POST['content3'];
    $content4 = $_POST['content4'];
    $content5 = $_POST['content5'];
    $content6 = $_POST['content6'];
    $img = "<img src=\"head.PNG\"/>";
    if(empty($content1))
    {
      $error = 'Please Fill out all of the feilds';
    }
    else
    {
      include_once('dompdf/dompdf_config.inc.php' );
     
     $dompdf = new DOMPDF();
     $dompdf -> load_html($name);
     $dompdf -> load_html($img);
     $dompdf -> load_html($content1);
     $dompdf -> load_html($content2);
     $dompdf -> load_html($content3);
     $dompdf -> load_html($content4);
     $dompdf -> load_html($content5);
     $dompdf -> load_html($content6);
     $dompdf -> render();
     $dompdf -> stream('Sample.pdf');
    }
       
  }

  ?>
<html>
  <body>
    <?php if(isset($error)) {echo $error;}?>
    <form method="post" action="index1.php">
      <img src="head.PNG" name="img" width="200px" align="left">
      <p>Name<textarea name="name"></textarea></p>
      <p>Temporalis<textarea name="content1"></textarea></p>
      <p>Orbicularis occuli<textarea name="content2"></textarea></p>
      <p>Sternoclediomastoid<textarea name="content3"></textarea></p>
      <p>Orbicularis oris<textarea name="content4"></textarea></p>
      <p>Massefer<textarea name="content5"></textarea></p>
      <p>Platysma<textarea name="content6"></textarea></p>
      <input type="submit" name="submit" id="submit"/>
     
    </form>
  </body>
</html>


any help to get this to output all of the fields and the image, it would be much appreciated.
many thanks
Steve
zenko44
New php-forum User
New php-forum User
 
Posts: 3
Joined: Fri Apr 12, 2013 8:58 am

Re: PHP to PDF probems

Postby seandisanti » Fri Apr 12, 2013 11:44 am

It looks like your calls to $dompdf -> load_html() are overwriting the same value. The easy solution is to concatenate your fields first. I'd say just at the beginning do:
Code: Select all

 
<?php
if($_POST &&!empty($_POST['content1'])) {
    
$content '';
    foreach (
$_POST as $key => $value) {
        if (
$key == 'name') {
            
$name $value;
        } else {
            
$content .= $value;
        }
    }
    
$img "<img src=\"head.PNG\"/>";

    include_once(
'dompdf/dompdf_config.inc.php' );

    
$dompdf = new DOMPDF();
    
$dompdf->load_html($name);
    
$dompdf->load_html($img);
    
$dompdf->load_html($content);
    
$dompdf->render();
    
$dompdf->stream('Sample.pdf');
}
?>
<html>
    <body>
        <?php
        
if (isset($error)) {
            echo 
$error;
        }
        
?>
        <form method="post" action="index1.php">
            <img src="head.PNG" name="img" width="200px" align="left">
            <p>Name<textarea name="name"></textarea></p>
            <p>Temporalis<textarea name="content1"></textarea></p>
            <p>Orbicularis occuli<textarea name="content2"></textarea></p>
            <p>Sternoclediomastoid<textarea name="content3"></textarea></p>
            <p>Orbicularis oris<textarea name="content4"></textarea></p>
            <p>Massefer<textarea name="content5"></textarea></p>
            <p>Platysma<textarea name="content6"></textarea></p>
            <input type="submit" name="submit" id="submit"/>

        </form>
    </body>
</html>


***edit*** minor change to code
seandisanti
php-forum Fan User
php-forum Fan User
 
Posts: 838
Joined: Mon Oct 01, 2012 12:32 pm

Re: PHP to PDF probems

Postby zenko44 » Sun Apr 14, 2013 3:13 pm

right, it know takes in all the inputs but unfortunately it still only loads the last, load_html($stuff)
is their anyway to get dompdf to show all three of them or is their another type of load html
zenko44
New php-forum User
New php-forum User
 
Posts: 3
Joined: Fri Apr 12, 2013 8:58 am

Re: PHP to PDF probems

Postby johnj » Sun Apr 14, 2013 7:37 pm

Did you try $dompdf->load_html($name.$img.$content); ?
johnj
php-forum Super User
php-forum Super User
 
Posts: 1805
Joined: Thu Mar 10, 2011 5:07 pm

Re: PHP to PDF probems

Postby zenko44 » Sun Apr 14, 2013 11:57 pm

Thank you very much with that bit it helped, i was using comma instead of full stop which confused me for ages.

if i run into any problems i will re-activate this post.

many thanks
for everyone involved help
zenko44
New php-forum User
New php-forum User
 
Posts: 3
Joined: Fri Apr 12, 2013 8:58 am


Return to PHP coding => General

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 3 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.