I'm a new programmer, just so you're aware.
$pdf = new Pdf("./Field Sheets Fill-In HOUSE v2.1.pdf");
$pdf->fillForm($data)
->saveAs('./completed/' . $filename);
$checklistPdf = new Pdf("./Checklist - HOUSE.pdf");
$checklistPdf->fillForm($data)
->saveAs('./checklistCompleted/' . $checklistFilename);
// if ($_SESSION['mainInspector'] == 'rick' || $_SESSION['mainInspector'] == 'Rick') {
// $rickScopePdf = new Pdf("./Scope and Terms RICK");
// $pdf->fillForm($data)
// ->saveAs('./scopeCompleted/' . $scopeFilename);
// } else if ($_SESSION['mainInspector'] == 'joey' || $_SESSION['mainInspector'] == 'Joey') {
// $joeyScopePdf = new Pdf("./Scope and Terms JOEY");
// $pdf->fillForm($data)
// ->saveAs('./scopeCompleted/' . $scopeFilename);
// } else {
// echo 'error with scope.';
// };
In the above code, you can see that the uncommented section takes a file I've specified e.g. 'Field Sheets Fill-in ...' & 'Checklist - HOUSE.pdf', fills the PDF using the HTML form data and saves it in a specific location as a specific filename.
In the commented out section, I created an if statement to try an make it choose which .pdf to fill based on the html data that was submitted.
In other words, if 'Rick' or 'rick' was input for the var 'mainInspector' I wanted it to choose the PDF file 'Scope and Terms RICK'. If 'Joey' or 'joey' was input I wanted it to choose the PDF 'Scope and Terms JOEY'. Else, I wanted it to echo 'error...'.
I'm using PDFtk to make this whole thing work, and the code below can be found in a class. (Granted, I don't really know exactly what a class is or why it's necessary)
Also to note, everything else, e.g. the uncommented code, works perfectly fine. I've just got about 4 different instances that I want to be able to choose the specific file based on form data with an if statement or something along those lines.
Any guidance would be greatly appreciated.
***** Error message that appears when it's not commented out is as follows:
If I uncomment that and try to run it, it throws the following error message. I can't figure out why.
Fatal error: Uncaught Exception: Operation was already executed in C:\Users\ansba\Desktop\HTML to PDF\vendor\mikehaertl\php-pdftk\src\Command.php:246 Stack trace: #0 C:\Users\ansba\Desktop\HTML to PDF\vendor\mikehaertl\php-pdftk\src\Command.php(90): mikehaertl\pdftk\Command->checkExecutionStatus() #1 C:\Users\ansba\Desktop\HTML to PDF\vendor\mikehaertl\php-pdftk\src\Pdf.php(277): mikehaertl\pdftk\Command->setOperation('fill_form') #2 C:\Users\ansba\Desktop\HTML to PDF\classes\GeneratePDF.php(31): mikehaertl\pdftk\Pdf->fillForm(Object(mikehaertl\pdftk\XfdfFile)) #3 C:\Users\ansba\Desktop\HTML to PDF\generate.php(124): Classes\GeneratePDF->generate(Array) #4 {main} thrown in C:\Users\ansba\Desktop\HTML to PDF\vendor\mikehaertl\php-pdftk\src\Command.php on line 246