<?php // Stuck? This code originated from the MODX Community Forums: https://tinyurl.com/ychan98k require_once('/path/to/php-pdftk/vendor/autoload.php'); // Server path to php-pdftk use mikehaertl\pdftk\Pdf; // Fill form with data array $pdf = new Pdf($modx->getOption('core_path') . 'components/php-pdftk/yourForm.pdf'); // Path to your blank template PDF $pdf->fillForm([ // This is where you need to map PDF fields to Web Fields 'First Name' => $hook->getValue('first-name'), 'Last Name' => $hook->getValue('last-name') ]) ->needAppearances() ->execute(); // Grab the temp PDF file that we just dynamically created $attachment = $pdf->getTmpFile(); // Add the PDF as an email attachment $modx->getService('mail', 'mail.modPHPMailer'); $modx->mail->mailer->AddAttachment($attachment); return true;
[[!FormIt? &hooks=`formit2pdf, email, redirect` &emailTo=`[email protected]` &emailSubject=`New application` &emailFrom=`[email protected]` &emailTpl=`myEmailTpl` &redirectTo=`2` ]]
<input type="text" name="first-name" placeholder="first-name" value="[[!+fi.first-name]]"> <input type="text" name="last-name" placeholder="last-name" value="[[!+fi.last-name]]">
Congratulations, you have a new application from: <strong>[[+first-name]] [[+last-name]]</strong>. <br><br> We've processed their form submission and attached it to this email for you.
<?php // Stuck? This code originated from the MODX Community Forums: https://tinyurl.com/ychan98k require_once('/path/to/php-pdftk/vendor/autoload.php'); // Server path to php-pdftk use mikehaertl\pdftk\Pdf; // Fill form with data array $pdf = new Pdf($modx->getOption('core_path') . 'components/php-pdftk/yourForm.pdf'); // Path to your blank template PDF $pdf->fillForm([ // This is where you need to map PDF fields to Web Fields 'First Name' => $hook->getValue('first-name'), 'Last Name' => $hook->getValue('last-name') ]) ->needAppearances() ->saveAs($modx->getOption('core_path') . 'components/php-pdftk/populatedForm.pdf'); // Save the populated form here return true;