hello,
I have a code to send my form with dompdf to a pdf file. Everything works except the php result. I can't display the php result of $total on my pdf.. Hope someone can help me!! You can find my code if you follow the link
<?php
if (!empty($_POST)) {
// Used for later to determine result
$success = $error = false;
// Object syntax looks better and is easier to use than arrays to me
$post = new stdClass;
// Usually there would be much more validation and filtering, but this
// will work for now.
foreach ($_POST as $key => $val)
$post->$key = trim(strip_tags($_POST[$key]));
// Check for blank fields
if (empty($post->name) OR empty($post->email))
$error = true;
else {
// Get this directory, to include other files from
$dir = dirname(__FILE__);
// Get the contents of the pdf into a variable for later
ob_start();
require_once($dir.'/pdf.php');
$pdf_html = ob_get_contents();
ob_end_clean();
// Load the dompdf files
require_once($dir.'/dompdf/dompdf_config.inc.php');
$dompdf = new DOMPDF(); // Create new instance of dompdf
$dompdf->load_html($pdf_html); // Load the html
$dompdf->render(); // Parse the html, convert to PDF
$pdf_content = $dompdf->output(); // Put contents of pdf into variable for later
// Get the contents of the HTML email into a variable for later
ob_start();
require_once($dir.'/html.php');
$html_message = ob_get_contents();
ob_end_clean();
// Load the SwiftMailer files
require_once($dir.'/swift/swift_required.php');
$mailer = new Swift_Mailer(new Swift_MailTransport()); // Create new instance of SwiftMailer
$message = Swift_Message::newInstance()
->setSubject('How To Create and Send An HTML Email w/ a PDF Attachment') // Message subject
->setTo(array($post->email => $post->name)) // Array of people to send to
->setFrom(array('[email protected]' => 'Nettuts+')) // From:
->setBody($html_message, 'text/html') // Attach that HTML message from earlier
->attach(Swift_Attachment::newInstance($pdf_content, 'nettuts.pdf', 'application/pdf')); // Attach the generated PDF from earlier
// Send the email, and show user message
if ($mailer->send($message))
$success = true;
else
$error = true;
}
}
$sympathisant=250;
$brons=1000;
$zilver=1500;
$goud=2000;
$perssymp=125;
$persbrons=125;
$perszilver=125;
$persgoud=125;
$table_price=20;
$chair_price=5;
$drinks_price=2;
$snacks_price=1;
$total=0;
if(isset($_POST['sympathisant']) && $_POST['sympathisant']=='1')
{
$total=$total+$sympathisant;
}
if(isset($_POST['brons']) && $_POST['brons']=='1')
{
$total=$total+$brons;
}
if(isset($_POST['zilver']) && $_POST['zilver']=='1')
{
$total=$total+$zilver;
}
if(isset($_POST['goud']) && $_POST['goud']=='1')
{
$total=$total+$goud;
}
if(isset($_POST['drinks']))
{
$num=(int)$_POST['drinks']; // make sure only integers are accepted
if($num>=1) // ignore negative values
{
$total=$total+($perssymp*$num);
}
}
if(isset($_POST['perssymp']))
{
$num=(int)$_POST['perssymp']; // make sure only integers are accepted
if($num>1) // ignore negative values
{
$total=$total+($perssymp*$num-125);
}
}
if(isset($_POST['persbrons']))
{
$num=(int)$_POST['persbrons']; // make sure only integers are accepted
if($num>4) // ignore negative values
{
$total=$total+($persbrons*$num-500);
}
}
if(isset($_POST['perszilver']))
{
$num=(int)$_POST['perszilver']; // make sure only integers are accepted
if($num>6) // ignore negative values
{
$total=$total+($perszilver*$num-750);
}
}
if(isset($_POST['persgoud']))
{
$num=(int)$_POST['persgoud']; // make sure only integers are accepted
if($num>8) // ignore negative values
{
$total=$total+($persgoud*$num-1000);
}
}
echo "<p>Total price is \$$total</p>\n";
?>
{table}
<form id="pricecalculation" method="post" action="">
<table>
<tr>
<td><label for="name">Your Name:</label></td>
<td><input type="text" name="name" id="name" class="input" /></td>
<td><label for="email">Your Email:</label>
<td><input type="text" name="email" id="email" class="input" /></td>
<tr>
<td>Sympathisant</td>
<td><input type="checkbox" name="sympathisant" value="1" />Yes</td>
<td><input type="hidden" name="foo" value="0" /></td>
<tr>
<td>Hoeveel personen? </td>
<td><input name="perssymp" type="text" id="perssymp" size="3"></td>
</tr>
</br>
<tr>
<td>Brons</td>
<td><input type="checkbox" name="brons" value="1" />Yes</td>
<td><input type="hidden" name="foo" value="0" /></td>
</tr>
<tr>
<td>Hoeveel personen? </td>
<td><input name="persbrons" type="text" id="persbrons" size="3"></td>
</tr>
<br>
<tr>
<td>Zilver</td>
<td><input type="checkbox" name="zilver" value="1" />Yes</td>
<td><input type="hidden" name="foo" value="0" /></td>
</tr>
<tr>
<td>Hoeveel personen?</td>
<td><input name="perszilver" type="text" id="perszilver" size="3"></td>
</tr>
<tr>
</br>
<tr>
<td>Goud</td>
<td><input type="checkbox" name="goud" value="1" />Yes</td>
<td><input type="hidden" name="foo" value="0" /></td>
</tr>
<tr>
<td>Hoeveel personen? </td>
<td><input name="persgoud" type="text" id="persgoud" size="3"></td>
</tr>
</table>
<div id='total' name='total'>
<script type="text/php">
echo "<p>Total price is \$$total</p>\n";
</script>
</div>
<input name="submit" type="submit" value="Calculate price"/>
</form>
[/table]
1.999 views