The following is the code I use in an Order Confirmation module. I am creating a pdf file using fpdf
and also sending an email. Subsequently, I clear out a shopping cart and redisplay the menu.
In the code below, I have commented out the creation of the pdf file. When I do this the email is sent and the cart is emptied by the javascript code
<script type="text/javascript">
doCart(\'EmptyCart\',\'0\', \'0\', \' \', \'partCheckOut\');
</script>
but if I uncomment the code for the creation of the pdf:
$pdf->getHdrDtl();
$pdf->Header();
$pdf->Footer();
$pdf->generatePDF();
the pdf file is created, the email is sent, but the cart is not emptied and the menu is not redisplayed.
Does anyone have any suggestions or ideas?
if (isset($_POST['confirm']))
{
$Cart->ConfirmOrder();
/*
$pdf->getHdrDtl();
$pdf->Header();
$pdf->Footer();
$pdf->generatePDF();
*
*/
$Cart->sendOrderEmails($dealer_email);
echo '
<script type="text/javascript">
doCart(\'EmptyCart\',\'0\', \'0\', \' \', \'partCheckOut\');
</script>
';
$group = $_SESSION['group'];
if ($group == 1){
header("Refresh: 1; ./admin_menu.php");
exit;
}
if ($group == 2){
header("Refresh: 1; ./user_menu.php");
exit;
}
if ($group == 3){
header("Refresh: 1; ./admin_menu.php");
exit;
}
}
I don't know how your $pdf->generatePDF() is acting, but it looks like it generate the PDF inside the current page. The page is no more an HTML page but a PDF one. Consequently you can't write any javascript code into the page (or any html or text directly, you must use the FPDF functions to insert data into the PDF, and before the generation of the document).
And you definitely can't send any PHP header after sending data to the browser. If you have to redirect after sending data, use javascript redirections.