I have been following several topics on wordpress.org about saving the data submitted in Contact Form 7 and sending it to the the submitter as a PDF attachment.
https://wordpress.org/support/topic/convert-pdf-file
Exporting form results from Contact form 7 to PDF (fPDF)
Im using Kory's php in my functions and have uploaded fpdf to me theme file in a folder called fpdf plus added in [attachments] to my contact form in wordpress admin.
My error is that the contact form doesn't submit. Just loads. Any ideas?
My Form - http://www.mikeandtom.co.uk/ctest
The php error noted was originally: '
FPDF error: Undefined font: times-roman B' - research on this revealed the font folder should be defined:
define('FPDF_FONTPATH',get_template_directory().'fpdf/font/'); define ('FPDF_PATH',get_template_directory().'/fpdf/');
require(FPDF_PATH.'fpdf.php');
ALTHOUGH THIS THROWS UP A 'could not define font definition file' error
add_action('wpcf7_before_send_mail', 'wpcf7_update_email_body');
function wpcf7_update_email_body($contact_form) {
$submission = WPCF7_Submission::get_instance();
if ( $submission ) {
define ('FPDF_PATH',get_template_directory().'/fpdf/');
require(FPDF_PATH.'fpdf.php');
$posted_data = $submission->get_posted_data();
$name = $posted_data["your-name"];
$pdf = new FPDF();
$pdf->AddPage();
$pdf->SetFont('Times','B',16);
$pdf->Write(5,$name);
$pdf->Output(FPDF_PATH.'test.pdf', 'F');
}
}
add_filter( 'wpcf7_mail_components', 'mycustom_wpcf7_mail_components' );
function mycustom_wpcf7_mail_components($components){
if (empty($components['attachments'])) {
$components['attachments'] = array(FPDF_PATH .'test.pdf');
}
return $components;
}