Hello.
When i try to use
$pdf = $modules->get('RockPdf');
in a form hook in /site/ready.php then i get an 500 Server Error.
The hook without this line works, but when i include it then everything stops.
When i insert everything for creating PDF in a template PHP file in /site/templates/ then it works correctly. It generates the PDF without error:
$pdf = $modules->get('RockPdf');
$pdf->write('TEST');
$pdf->save('./generated_pdfs/' . date('yy-m-d_H_i') . '.pdf');
It's generated in /site/assets/RockPdf/generated_pdfs/.
But this same thing in the /site/ready.php file throws an error:
$forms->addHook('FormBuilderProcessor::emailFormReady',
function($e) {
$pdf = $modules->get('RockPdf');
$pdf->write('TEST');
$pdf->save('./generated_pdfs/' . date('yy-m-d_H_i') . '.pdf');
}
);
I get this from the errors.txt log file:
2020-12-14 11:24:21 guest PAGENAME Fatal Error: Uncaught Error: Call to a member function write() on null in SITEPATH/site/assets/cache/FileCompiler/site/ready.php:36 Stack trace: #0 SITEPATH/wire/core/WireHooks.php(813): ProcessWire\ProcessWire->{closure}(Object(ProcessWire\HookEvent)) #1 SITEPATH/wire/core/Wire.php(442): ProcessWire\WireHooks->runHooks(Object(ProcessWire\FormBuilderProcessor), 'emailFormReady', Array) #2 SITEPATH/site/modules/FormBuilder/FormBuilder/FormBuilderProcessor.php(1237): ProcessWire\Wire->__call('emailFormReady', Array) #3 SITEPATH/wire/core/Wire.php(386): ProcessWire\FormBuilderProcessor->___emailForm(Object(ProcessWire\InputfieldForm), Array) #4 SITEPATH/wire/core/WireHooks.php(723): ProcessWire\Wire->_callMethod('___emailForm', Array) #5
SITEPATH/wire/core/Wire.ph (Zeile 36 in SITEPATH/site/assets/cache/FileCompiler/site/ready.php)
If someone could help me, I would greatly appreciate it. My goal is to generate a PDF on form submission and attach it to the email that is sent to the admin.
Thanks in advance.
Daniel