[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

if (empty($_POST['Ignore'])) email not being sent - fpdf applicaiton

Posted on 2009-05-06
4
Medium Priority
?
785 Views
Last Modified: 2012-05-06
hi -

you'll see this line in the code:

//attempt to stop pdf from generating from the server WITHOUT  a form submission
if (empty($_POST['Ignore'])) {
    $pdfcontent = $pdf->Output("helloworld.pdf", "S")
        or exit("unable to send pdf");
}

the fpdf code below  generates an email with a pdf attachment - i added the code above because we're getting blank submissions -in other words, emails sent with blank pdfs. the pdfs open but they are not filled in. when i add the code above the email does not send even when i fill out the form. - see entire page of fpdf code below:
<?php error_reporting(7); if ($_GET['hdwtest']=='captchainstalled') { echo 'Captcha verification code installed.'; exit; } if (count($_POST) > 0 || count($_GET) > 4) { @session_start(); foreach ($_GET as $item => $value)@setcookie ('hdw_'.$item, $value, 0, '/');foreach ($_POST as $item => $value)@setcookie ('hdw_'.$item, $value, 0, '/');foreach ($_COOKIE as $item => $value)	  if (substr($item,0,4) == 'hdw_' && $_GET[substr($item,4)] == '' && $_POST[substr($item,4)] == '')@setcookie ($item, '', 0, '/'); if ((empty($_POST['hdcaptcha']) || $_POST['hdcaptcha'] == '' || strtolower($_POST['hdcaptcha']) != strtolower($_SESSION['rand_code'])) && (empty($_GET['hdcaptcha']) || $_GET['hdcaptcha'] == '' || strtolower($_GET['hdcaptcha']) != strtolower($_SESSION['rand_code']))) {if ($_POST['hdwfail'] != '')header('Location: '.$_POST['hdwfail']);else	header('Location: '.$_GET['hdwfail']);exit;} foreach ($_COOKIE as $item => $value) if (substr($item,0,4) == 'hdw_')@setcookie ($item, '', 0, '/'); } reset($_POST);reset($_GET); ?>
<?php
require('fpdf/fpdf.php');
$applicant = ($_POST['Patient_Name']);
 
class PDF extends FPDF
{
var $B;
var $I;
var $U;
var $HREF;
 
function PDF($orientation='P',$unit='mm',$format='A4')
{
    //Call parent constructor
    $this->FPDF($orientation,$unit,$format);
    //Initialization
    $this->B=0;
    $this->I=0;
    $this->U=0;
    $this->HREF='';
}
 
function WriteHTML($html)
{
    //HTML parser
    $html=str_replace("\n",' ',$html);
    $a=preg_split('/<(.*)>/U',$html,-1,PREG_SPLIT_DELIM_CAPTURE);
    foreach($a as $i=>$e)
    {
        if($i%2==0)
        {
            //Text
            if($this->HREF)
                $this->PutLink($this->HREF,$e);
            else
                $this->Write(5,$e);
        }
        else
        {
            //Tag
            if($e{0}=='/')
                $this->CloseTag(strtoupper(substr($e,1)));
            else
            {
                //Extract attributes
                $a2=explode(' ',$e);
                $tag=strtoupper(array_shift($a2));
                $attr=array();
                foreach($a2 as $v)
                    if(ereg('^([^=]*)=["\']?([^"\']*)["\']?$',$v,$a3))
                        $attr[strtoupper($a3[1])]=$a3[2];
                $this->OpenTag($tag,$attr);
            }
        }
    }
}
 
function OpenTag($tag,$attr)
{
    //Opening tag
    if($tag=='B' or $tag=='I' or $tag=='U')
        $this->SetStyle($tag,true);
    if($tag=='A')
        $this->HREF=$attr['HREF'];
    if($tag=='BR')
        $this->Ln(5);
}
 
function CloseTag($tag)
{
    //Closing tag
    if($tag=='B' or $tag=='I' or $tag=='U')
        $this->SetStyle($tag,false);
    if($tag=='A')
        $this->HREF='';
}
 
function SetStyle($tag,$enable)
{
    //Modify style and select corresponding font
    $this->$tag+=($enable ? 1 : -1);
    $style='';
    foreach(array('B','I','U') as $s)
        if($this->$s>0)
            $style.=$s;
    $this->SetFont('',$style);
}
 
function PutLink($URL,$txt)
{
    //Put a hyperlink
    $this->SetTextColor(0,0,255);
    $this->SetStyle('U',true);
    $this->Write(5,$txt,$URL);
    $this->SetStyle('U',false);
    $this->SetTextColor(0);
}
 
function Header()
{
    //Select Arial bold 12
    $this->SetFont('Arial','B',11);
	$this->SetTextColor(0,0,0);
    
    //Framed title
    $this->Cell(180,10,'Cornerstone Surgery Center',0,1,'C');
	$this->Cell(180,10,'PATIENT SURVEY',0,1,'C');
	//Line break
    $this->Ln(2);
	$this->SetTextColor(0,0,0);
$this->SetFont('Arial','B',8);
$this->Cell(90,5,'Patient Name:',0,0,'R');
$this->SetFont('Arial','I',8);
$this->Cell(90,5,$_POST['Patient_Name'],0,1,'L');
$this->SetFont('Arial','B',8);
$this->Cell(90,5,'Procedure Date:',0,0,'R');
$this->SetFont('Arial','I',8);
$this->Cell(90,5,$_POST['procedure_date'],0,1,'L');
$this->Ln(5);
 
	
}
function Footer()
{
    //Go to 1.5 cm from bottom
    $this->SetY(-15);
    //Select Arial italic 8
    $this->SetFont('Arial','I',8);
    //Print centered page number
    //Page number
	$this->SetTextColor(0,0,0);
    $this->Cell(0,10,'Page '.$this->PageNo().'/{nb}',0,0,'C');
}
}
 
$html='You can now easily print text mixing different
styles : <B>bold</B>, <I>italic</I>, <U>underlined</U>, or
<B><I><U>all at once</U></I></B>!<BR>You can also insert links
on text, such as <A HREF="http://www.fpdf.org">www.fpdf.org</A>,
or on an image: click on the logo.';
$authorize='I AUTHORIZE the doctor referenced above and such assistants as he may designate, to administer and conduct the exercise stress test. This test is designed to measure my fitness for work and/or sport, to determine the presence or absence of clinically significant heart disease, and/or evaluate the effectiveness of my current  therapy.<br><br>I understand that I will walk on a motor driven treadmill during the test or administered (i.e. Adenosine) medication through an intravenous line during the test. My electrocardiogram will be monitored and my blood pressure will  be measured. Exercise will be progressively increased until I attain a predetermined end point corresponding to moderate exercise stress, or become distressed in any way, or develop any abnormal response the physician considers significant, whichever of the above occurs first. <br><br>Every effort will be made to conduct the test in such a way as to minimize discomfort and risk. However, I understand that just as with other types of diagnostic tests, there are potential risks (approximately 2 to 3 per 10,000) associated with an exercise test. These include episodes of transient light-headedness, fainting, disorders of heart beat and very rarely the possibility of heart attack. I further understand that the laboratory is properly equipped for such situations and that its professional personnel are trained to administer any emergency care necessary. I voluntarily accept the risks associated with the above procedure. ';
			  
$agree='Please check with your pharmacy after 24 hours to allow us the needed time to process your prescription refill request. Click on the Submit button below to process your request.';			  
 
$pdf=new PDF();
$pdf->AliasNbPages();
$pdf->AddPage();
 
//Personal Info
$pdf->SetFont('Arial','B',9);
$pdf->SetTextColor(220,50,50);
$pdf->Cell(180,8,'Background Questions',1,1,'C');
$pdf->SetTextColor(0,0,0);
$pdf->SetFont('Arial','B',8);
$pdf->Cell(40,5,'Patient Sex:',1,0,'R');
$pdf->SetFont('Arial','I',8);
$pdf->Cell(50,5,$_POST['Patient_Sex'],1,0,'L');
$pdf->SetFont('Arial','B',8);
$pdf->Cell(40,5,'Patient Age:',1,0,'R');
$pdf->SetFont('Arial','I',8);
$pdf->Cell(50,5,$_POST['Patient_Age'],1,1,'L');
 
$pdf->SetTextColor(0,0,0);
$pdf->SetFont('Arial','B',8);
$pdf->Cell(40,5,'Physician:',1,0,'R');
$pdf->SetFont('Arial','I',8);
$pdf->Cell(140,5,$_POST['Physician'],1,1,'L');
$pdf->SetFont('Arial','B',8);
$pdf->MultiCell(180,5,'Was this your first visit to our Ambulatory Surgery Center?',1,1,'L');
$pdf->SetFont('Arial','I',8);
$pdf->Cell(180,5,$_POST['First_Visit'],1,1,'L');
 
$pdf->SetTextColor(0,0,0);
$pdf->SetFont('Arial','B',8);
$pdf->Cell(40,5,'Patient Name:',1,0,'R');
$pdf->SetFont('Arial','I',8);
$pdf->Cell(50,5,$_POST['Patient_Name'],1,0,'L');
$pdf->SetFont('Arial','B',8);
$pdf->Cell(40,5,'Telephone Number:',1,0,'R');
$pdf->SetFont('Arial','I',8);
$pdf->Cell(50,5,$_POST['Patient_Telephone'],1,1,'L');
 
 
//Registration
//HEADING
$pdf->SetTextColor(220,50,50);
$pdf->SetFont('Arial','B',9);
$pdf->Cell(180,8,'A. Registration',1,1,'C');
 
//QUESTIONS
$pdf->SetTextColor(0,0,0);
$pdf->SetFont('Arial','B',8);
$pdf->MultiCell(180,5,'Professional and courteous service of registration',1,1,'L');
$pdf->SetFont('Arial','I',8);
$pdf->Cell(180,5,$_POST['1_Registration'],1,1,'L');
 
$pdf->SetTextColor(0,0,0);
$pdf->SetFont('Arial','B',8);
$pdf->MultiCell(180,5,'Satisfactory answers to financial and insurance questions',1,1,'L');
$pdf->SetFont('Arial','I',8);
$pdf->Cell(180,5,$_POST['2_Registration'],1,1,'L');
 
$pdf->SetTextColor(0,0,0);
$pdf->SetFont('Arial','B',8);
$pdf->MultiCell(180,5,'Speed and efficiency of registration',1,1,'L');
$pdf->SetFont('Arial','I',8);
$pdf->Cell(180,5,$_POST['3_Registration'],1,1,'L');
 
//Facility
//HEADING
$pdf->SetTextColor(220,50,50);
$pdf->SetFont('Arial','B',9);
$pdf->Cell(180,8,'B. Facility',1,1,'C');
 
//QUESTIONS
$pdf->SetTextColor(0,0,0);
$pdf->SetFont('Arial','B',8);
$pdf->MultiCell(180,5,'Comfort of the registration waiting area ',1,1,'L');
$pdf->SetFont('Arial','I',8);
$pdf->Cell(180,5,$_POST['1_Facility'],1,1,'L');
 
$pdf->SetTextColor(0,0,0);
$pdf->SetFont('Arial','B',8);
$pdf->MultiCell(180,5,'Comfort of your seat or resting area in the Center ',1,1,'L');
$pdf->SetFont('Arial','I',8);
$pdf->Cell(180,5,$_POST['2_Facility'],1,1,'L');
 
$pdf->SetTextColor(0,0,0);
$pdf->SetFont('Arial','B',8);
$pdf->MultiCell(180,5,'Attractiveness of the surgery center',1,1,'L');
$pdf->SetFont('Arial','I',8);
$pdf->Cell(180,5,$_POST['3_Facility'],1,1,'L');
 
$pdf->SetTextColor(0,0,0);
$pdf->SetFont('Arial','B',8);
$pdf->MultiCell(180,5,'Cleanliness of the surgery center ',1,1,'L');
$pdf->SetFont('Arial','I',8);
$pdf->Cell(180,5,$_POST['4_Facility'],1,1,'L');
 
//Nursing
//HEADING
$pdf->SetTextColor(220,50,50);
$pdf->SetFont('Arial','B',9);
$pdf->Cell(180,8,'C. Nursing',1,1,'C');
 
//QUESTIONS
$pdf->SetTextColor(0,0,0);
$pdf->SetFont('Arial','B',8);
$pdf->MultiCell(180,5,'Waiting time before your surgery or procedure began',1,1,'L');
$pdf->SetFont('Arial','I',8);
$pdf->Cell(180,5,$_POST['1_Nursing'],1,1,'L');
 
$pdf->SetTextColor(0,0,0);
$pdf->SetFont('Arial','B',8);
$pdf->MultiCell(180,5,'Explanation the physician gave you about the surgery or procedure',1,1,'L');
$pdf->SetFont('Arial','I',8);
$pdf->Cell(180,5,$_POST['2_Nursing'],1,1,'L');
 
$pdf->SetTextColor(0,0,0);
$pdf->SetFont('Arial','B',8);
$pdf->MultiCell(180,5,'Professional and courteous service of the nurses ',1,1,'L');
$pdf->SetFont('Arial','I',8);
$pdf->Cell(180,5,$_POST['3_Nursing'],1,1,'L');
 
$pdf->SetTextColor(0,0,0);
$pdf->SetFont('Arial','B',8);
$pdf->MultiCell(180,5,'Skill of the nurse starting IV ',1,1,'L');
$pdf->SetFont('Arial','I',8);
$pdf->Cell(180,5,$_POST['4_Nursing'],1,1,'L');
 
$pdf->SetTextColor(0,0,0);
$pdf->SetFont('Arial','B',8);
$pdf->MultiCell(180,5,'Nurses explaining procedures  ',1,1,'L');
$pdf->SetFont('Arial','I',8);
$pdf->Cell(180,5,$_POST['5_Nursing'],1,1,'L');
 
$pdf->SetTextColor(0,0,0);
$pdf->SetFont('Arial','B',8);
$pdf->MultiCell(180,5,'Nurses concern for your comfort ',1,1,'L');
$pdf->SetFont('Arial','I',8);
$pdf->Cell(180,5,$_POST['6_Nursing'],1,1,'L');
 
$pdf->SetTextColor(0,0,0);
$pdf->SetFont('Arial','B',8);
$pdf->MultiCell(180,5,'Nurses courtesy towards family who accompanied you (if applicable)',1,1,'L');
$pdf->SetFont('Arial','I',8);
$pdf->Cell(180,5,$_POST['7_Nursing'],1,1,'L');
 
$pdf->SetTextColor(0,0,0);
$pdf->SetFont('Arial','B',8);
$pdf->MultiCell(180,5,'Instructions nurses gave about caring for yourself at home ',1,1,'L');
$pdf->SetFont('Arial','I',8);
$pdf->Cell(180,5,$_POST['8_Nursing'],1,1,'L');
 
//PersonalIssues
//HEADING
$pdf->SetTextColor(220,50,50);
$pdf->SetFont('Arial','B',9);
$pdf->Cell(180,8,'D. Personal Issues',1,1,'C');
 
//QUESTIONS
$pdf->SetTextColor(0,0,0);
$pdf->SetFont('Arial','B',8);
$pdf->MultiCell(180,5,'Information provided about delays (if you experienced delays) ',1,1,'L');
$pdf->SetFont('Arial','I',8);
$pdf->Cell(180,5,$_POST['1_PersonalIssues'],1,1,'L');
 
$pdf->SetTextColor(0,0,0);
$pdf->SetFont('Arial','B',8);
$pdf->MultiCell(180,5,'Our concern for your privacy  ',1,1,'L');
$pdf->SetFont('Arial','I',8);
$pdf->Cell(180,5,$_POST['2_PersonalIssues'],1,1,'L');
 
$pdf->SetTextColor(0,0,0);
$pdf->SetFont('Arial','B',8);
$pdf->MultiCell(180,5,'Degree to which your pain was controlled  ',1,1,'L');
$pdf->SetFont('Arial','I',8);
$pdf->Cell(180,5,$_POST['3_PersonalIssues'],1,1,'L');
 
$pdf->SetTextColor(0,0,0);
$pdf->SetFont('Arial','B',8);
$pdf->MultiCell(180,5,'Response to concerns/complaints made during your visit ',1,1,'L');
$pdf->SetFont('Arial','I',8);
$pdf->Cell(180,5,$_POST['4_PersonalIssues'],1,1,'L');
 
//OverallAssessment
//HEADING
$pdf->SetTextColor(220,50,50);
$pdf->SetFont('Arial','B',9);
$pdf->Cell(180,8,'E. Overall Assessment',1,1,'C');
 
//QUESTIONS
$pdf->SetTextColor(0,0,0);
$pdf->SetFont('Arial','B',8);
$pdf->MultiCell(180,5,'Overall rating of care received during your visit',1,1,'L');
$pdf->SetFont('Arial','I',8);
$pdf->Cell(180,5,$_POST['1_OverallAssessment'],1,1,'L');
 
$pdf->SetTextColor(0,0,0);
$pdf->SetFont('Arial','B',8);
$pdf->MultiCell(180,5,'Degree to which staff worked together to care for you',1,1,'L');
$pdf->SetFont('Arial','I',8);
$pdf->Cell(180,5,$_POST['2_OverallAssessment'],1,1,'L');
 
$pdf->SetTextColor(0,0,0);
$pdf->SetFont('Arial','B',8);
$pdf->MultiCell(180,5,'Likelihood of your recommending our Ambulatory Surgery Center to others ',1,1,'L');
$pdf->SetFont('Arial','I',8);
$pdf->Cell(180,5,$_POST['3_OverallAssessment'],1,1,'L');
 
$pdf->SetTextColor(0,0,0);
$pdf->SetFont('Arial','B',8);
$pdf->MultiCell(180,5,'Comments (describe good or bad experiences):',1,1,'L');
$pdf->SetFont('Arial','I',8);
$pdf->MultiCell(180,5,$_POST['4_OverallAssessment'],1,1,'L');
 
//TESTING FOR BLANK PDF
$pdf->MultiCell(180,5,'Ignore this field:',1,1,'L');
$pdf->SetFont('Arial','I',8);
$pdf->MultiCell(180,5,$_POST['Ignore'],1,1,'L');
 
$pdf->MultiCell(180,5,'Remote Address (for testing purposes):',1,1,'L');
$pdf->SetFont('Arial','I',8);
$pdf->MultiCell(180,5,$_SERVER['REMOTE_ADDR'],1,1,'L');
 
//attempt to stop pdf from generating from the server WITHOUT  a form submission
if (empty($_POST['Ignore'])) {
    $pdfcontent = $pdf->Output("helloworld.pdf", "S")
        or exit("unable to send pdf");
}
################################################################################
################################################################################
//output to e-mail 
//output to e-mail 
require_once('fpdf/Mail.php');
require_once('fpdf/Mail_Mime/mime.php');
 
// email address of the recipient
$to = "meg@cornerstonesurgerycenter.com";
 
 
 
 
// email address of the sender
$from = "donotreply@cornerstonesurgerycenter.com";
 
// subject of the email
$subject = 'Patient Survey Submission from:  '.$applicant;
 
// email header format complies the PEAR's Mail class
// this header includes sender's email and subject
$headers = array(       'From' => $from,
                                'Subject' => $subject,
                                'Cc' => "elkinhimer@sbcglobal.net");
 
// We will send this email as HTML format
// which is well presented and nicer than plain text
// using the heredoc syntax
// REMEMBER: there should not be any space after PDFMAIL keyword
$htmlMessage = <<<PDFMAIL
<html>
<body bgcolor="#ffffff">
<p align="left">
You have received this automated
mailing from the Cornerstone Surgery Center.
Please do not respond to this email. This message
contains an attached Patient Survey.
</p>
</body>
</html>
PDFMAIL;
 
// create a new instance of the Mail_Mime class
$mime = new Mail_Mime();
 
// set HTML content
$mime->setHtmlBody($htmlMessage);
 
// IMPORTANT: add pdf content as attachment
$mime->addAttachment($pdfcontent, 'application/pdf', 'Cornerstone_Patient_Survey.pdf', false, 'base64');
 
// build email message and save it in $body
$body = $mime->get();
 
// build header
$hdrs = $mime->headers($headers);
 
// create Mail instance that will be used to send email later
$mail = &Mail::factory('mail');
 
// Sending the email, according to the address in $to,
// the email headers in $hdrs,
// and the message body in $body.
if ($_POST['Ignore']=="") {;} else {
$mail->send($to, $hdrs, $body);}
 
header ('Location: http://cornerstonesurgerycenter.com/survey_thanks.php')
or exit("unable to send pdf ($mail)");
?>

Open in new window

0
Comment
Question by:phillystyle123
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 2

Expert Comment

by:danls
ID: 24320825
I don't know if I understand your issue correctly.

From the snippet you added it seems that, if the form variable 'ignore' is empty you will then assign the PDF content. If no form is posted this variable will be empty so I don't really understand how you use that variable.


If appears that you have a CAPTCHA field in that form. So how would it be possible to pass the captcha test if no form was submitted.

Could you problem be related to the actual PDF class?

Could you give some more details as to when exactly the problem happens?
0
 

Author Comment

by:phillystyle123
ID: 24321085
it seems to happen inadvertantly  - with my 'ignore' snippet - i'm trying to acheive: if ignore field is empty then the email and pdf attachment WILL NOT be sent. on 2nd look, it seems like my logic is all wrong - shouldn't it be something like:

//attempt to stop pdf from generating from the server WITHOUT  a form submission
if (empty($_POST['some_required_field'])) {
    $pdfcontent = $pdf->Output("helloworld.pdf", "S")
        or exit("unable to send pdf");
}

so, if "some_required_field" is not filled out, then the form will not send - will the snippet above acheive this?

0
 
LVL 2

Accepted Solution

by:
danls earned 2000 total points
ID: 24321267
I would completely change this. At the beginning of the file add something like (prior to creating the PDF object):

if (empty($_POST['some_required_field'])) {
  echo "Please submit the form."
  exit();
}

Or even better:

if (empty($_POST['some_required_field'])) {
  header('Location: youroriginalformpage.php?errorCode=X');
  exit();
}

And in youroriginalformpage.php:

if(isset($_GET['errorCode']) && $_GET['errorCode'] == 'X')
{
 echo 'Please submit the form below in order to continue';
}

That way, if no form submission was made, you would redirect the users to the actual form page, with a proper error message.

Regards,

D
0
 

Author Closing Comment

by:phillystyle123
ID: 31578584
thank you so much - works perfectly - hopefully this will fix the issue
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Suggested Courses

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question