homepage Welcome to WebmasterWorld Guest from 54.204.141.129
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
phpmailer and checkboxes
jaybaker




msg:3820615
 12:09 am on Jan 7, 2009 (gmt 0)

Hello all, I have two bugs that I need to get fixed and your help would be greatly appreciated. First off my script works but only if zip files are not added. I fill in the form and set in a file box a zip file, hit submit and the script seems to work but none of the values go through and the zip file does not attach. The second issue is that I have eleven checkboxes with nine of them populating correctly. but when I open the fdf with the pdf two of the check boxes do not show through. All names are the same across all three files. What am I doing wrong? You can check it out at <snip>.

Thanks

[edited by: eelixduppy at 5:29 am (utc) on Jan. 7, 2009]
[edit reason] no URLs, please [/edit]

 

eelixduppy




msg:3820790
 5:30 am on Jan 7, 2009 (gmt 0)

Can you please elaborate on your issues a bit more so that we may help you. Possibly post some relevant code.

jaybaker




msg:3820797
 6:13 am on Jan 7, 2009 (gmt 0)

Here is the code for the form

<p>Fill in the form with all information possible. The date fields will be filled in when being processed.</p>
<form action="form2pdf.php" method="post" enctype="multipart/form-data" onsubmit="MM_validateForm('pname','','R','age','','RisNum','phone','','R','referredby','','R','signedby','','R','notes','','R');return document.MM_returnValue">
<table border="0" cellpadding="1" cellspacing="1">
<tr>
<td align="left">Patient Name:<br /><input type="text" name="pname" /></td><td align="left">Age:<br /><input type="text" name="age" size="4" /></td>
</tr>
<tr>
<td align="left">Phone Number:<br /><input type="text" name="phone" size="15" maxlength="14" /></td><td align="left">Date:<br /><input type="text" name="fdate" disabled="disabled" /></td>
</tr>
<tr>
<td colspan="2" align="left">Referred to:<input type="radio" name="referred2" value="Dr. One" />Dr. One<input type="radio" name="referred2" value="Dr Two" />Dr. Two <input type="radio" name="referred2" value="First Available" />First Available</td>
</tr>
<tr>
<td colspan="2" align="left">Referred by <input type="text" name="referredby" value="Dr. " /></td>
</tr>
<tr>
<td align="left" colspan="2">Please evaluate the following concern(s) and treat as necessary:</td>
</tr>
<tr>
<td align="center">
<table border="0">
<tr>
<td><input type="checkbox" name="develop" value="Developing Malocclusion" />Developing Malocclusion</td><td><input type="checkbox" name="idealtx" value="Determining Ideal Tx Time" />Determining Ideal Tx Time</td>
</tr>
<tr>
<td><input type="checkbox" name="habit" value="Habit Control" />Habit Control</td><td><input type="checkbox" name="toothteeth" id="missingteeth" value="Missing Tooth or Teeth" />
Missing Tooth/Teeth</td>
</tr>
<tr>
<td><input type="checkbox" name="impactions" value="Impaction(s)" />Impaction(s)</td><td><input name="possibleextractions" type="checkbox" id="possibleextractions" value="Possible Extractions" />
Possible Extractions</td>
<tr>
<td><input type="checkbox" name="sm" value="Space Maintenance" />Space Maintenance</td><td><input type="checkbox" name="tmj" value="T.M.J. Evaluation" />T.M.J. Evaluation</td>
</tr>
<tr>
<td><input type="checkbox" name="limitedt" value="Limited Treatment" />Limited Treatment</td><td><input type="checkbox" name="surgery" value="Possible Surgery" />Possible Surgery</td>
</tr>
<tr>
<td colspan="2"><input type="checkbox" name="others" value="Other" />Other<br /><textarea name="other" cols="50"></textarea></td>
</tr>
</table>
</td>
</tr>
<tr>
<td align="left" colspan="2">Notes:<br />
<textarea name="notes" cols="50"></textarea></td>
</tr>
<tr>
<td align="left">Signed:<input type="text" name="signedby" /></td><td align="left">Dated: <input type="text" name="dated" disabled="disabled" /></td>
</tr>
<tr>
<td align="left" colspan="2">Preferred Office Location: <input type="radio" name="officeloc" value="Santa Cruz" />Santa Cruz <input type="radio" name="officeloc" value="Aptos" />Aptos</td>
</tr>
<tr>
<td colspan="2"><p>Use the fields below to attach x-ray images to this form.</p></td>
</tr>
<?
$maxatt=5;
for($i=1;$i<=$maxatt;$i++){
echo "<tr><td colspan=2>File #".$i." <input type=file name='fileatt[]'></td></tr>";
}
?>
<tr>
<td><input type="submit" name="send" value="Submit" onclick="window.print();window.print();" /></td>
</tr>
</table>
</form>

Here is the code for the processing script

<? //heres where the fields are added to the array for the fdf file
require_once('createfdf.php');
require_once('class.phpmailer.php');
$today=date('m-d-Y',time());
$data=array();
$data['pname']=$_POST['pname'];
$data['age']=$_POST['age'];
$data['phone']=$_POST['phone'];
$data['fdate']=$today;
$data['referred2']=$_POST['referred2'];
$data['referredby']=$_POST['referredby'];
$data['develop']=$_POST['develop'];
$data['idealtx']=$_POST['idealtx'];
$data['habit']=$_POST['habit'];
$data['toothteeth']=$_POST['toothteeth']; // here is the one field that is not populating. I got one of the checkboxes to populate by deleting it in the pdf and adding it back in. I did so with this one and it didnt work.
$data['impactions']=$_POST['impactions'];
$data['possibleextractions']=$_POST['possibleextractions'];
$data['sm']=$_POST['sm'];
$data['tmj']=$_POST['tmj'];
$data['limitedt']=$_POST['limitedt'];
$data['surgery']=$_POST['surgery'];
$data['others']=$_POST['others'];
$data['other']=$_POST['other'];
$data['notes']=$_POST['notes'];
$data['signedby']=$_POST['signedby'];
$data['dated']=$today;
$data['officeloc']=$_POST['officeloc'];
$newpname=str_replace(" ","_",$_POST['pname']);
//below is where the fdf is created.
$fdf_file=$newpname.'.fdf';
$fdf_dir=dirname(__FILE__).'/results';
$pdf_doc="referralform.pdf";
$fdf_data=createFDF($pdf_doc,$data);
if($fp=fopen($fdf_dir.'/'.$fdf_file, 'w')){
fwrite($fp,$fdf_data,strlen($fdf_data));
echo $fdf_file.' written successfully.';
} else {
die('Unable to create the file '.$fdf_dir.'/'.$fdf_file);
}
fclose($fp);
// Mail code using PHP Mailer
$objMail = new PHPMailer();
$objMail->From = "donotreply@example.us";
$objMail->FromName = "Do Not Reply";
$objMail->Subject = "Referral form and xrays attached";
$objMail->IsHTML(true);
$objMail->Body = "Hello, Here is the referral form we have sent you.";
$objMail->AddAttachment($fdf_dir.'/'.$fdf_file, $fdf_file);
// Uploading Files
$files=array();
$files['file1']=$fdf_file; // here is where the fdf file is added
while(list($key,$value)=each($_FILES['fileatt']['name'])){
if(!empty($value)){
$filename=$value;
$filename=str_replace(" ","_",$filename);
$add="results/".$filename;
move_uploaded_file($_FILES['fileatt']['tmp_name'][$key],$add);
if(file_exists($add)==true) {
// Giving all permission to avoid any problem related to the attachment
chmod($add,0777);
// Attaching Files
$objMail->AddAttachment($add, $filename);
}
}
}
// Sending mail
$objMail->AddAddress("jason@example.us","");
$objMail->Send();
?>

Here is the code in the fdf file.

%FDF-1.2
%?
1 0 obj
<<
/FDF << /Fields [ <</T(pname)/V(Jane Doe)>><</T(age)/V(23)>><</T(phone)/V(555.555.5555)>><</T(fdate)/V(01-07-2009)>><</T(referred2)/V(Dr. One)>><</T(referredby)/V(#*$!x)>><</T(develop)/V(Developing Malocclusion)>><</T(idealtx)/V(Determining Ideal Tx Time)>><</T(habit)/V(Habit Control)>><</T(toothteeth)/V(Missing Tooth or Teeth)>><</T(impactions)/V(Impaction(s))>><</T(possibleextractions)/V(Possible Extractions)>><</T(sm)/V(Space Maintenance)>><</T(tmj)/V(T.M.J. Evaluation)>><</T(limitedt)/V(Limited Treatment)>><</T(surgery)/V(Possible Surgery)>><</T(others)/V(Other)>><</T(other)/V(#*$!)>><</T(notes)/V(#*$!)>><</T(signedby)/V(John Doe)>><</T(dated)/V(01-07-2009)>><</T(officeloc)/V(Santa Cruz)>>]
/F (referralform.pdf) /ID [ <f6f1f8409f930287666df4627559daa4>
] >>
>>
endobj
trailer
<<
/Root 1 0 R

>>
%%EOF

Any help would be greatly appreciated.

[edited by: coopster at 1:42 pm (utc) on Jan. 7, 2009]
[edit reason] exemplified details [/edit]

jezra




msg:3820820
 8:19 am on Jan 7, 2009 (gmt 0)

You should add some error checking to make sure that the file was uploaded properly and that the file isn't so large that it violates the PHP upload_max_file_size or the PHP post_max_size config settings.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved