• I’m trying to create a pdf attachment of my CF7 form’s post data. Using the following thread I was able to get the pdf attachment working. http://wordpress.org/support/topic/convert-pdf-file

    However I’m having trouble capturing the form’s post data.
    Does anyone have an idea how to capture the post data?

    This is what I have added my functions.php file:

    /* added pdf output */
    add_action( 'wpcf7_before_send_mail', 'save_application_form');
    function save_application_form($cf7) {
    
    /* GET EXTERNAL CLASSES */
    require(TEMPLATEPATH.'/includes/fpdf.php');
    
    /* example code to generate the pdf*/
    $pdf = new FPDF();
    $pdf->AddPage();
    $pdf->SetFont('times','B',16);
    $pdf->Write(5,"Testing pdf output\n\n\n");
    $values = $cf7->posted_data;
    $fname = $values['first-name'];
    $pdf->Write($fname);
    $pdf->Output(TEMPLATEPATH.'/file/pdf.pdf', 'F');
    
    /* add  the pdf as attach to the email */
    $cf7->uploaded_files = array ( 'attachedfile' =>  TEMPLATEPATH.'/file/pdf.pdf' );
    
    }

    https://wordpress.org/plugins/contact-form-7/

Viewing 1 replies (of 1 total)
  • I needed to accomplish the same thing and finally got the Contact Form 7 results to be converted to a PDF.

    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 CONSTANT AND GET FPDF CLASSES */
    define ('FPDF_PATH',get_template_directory().'/fpdf/'); // MAKE SURE THIS POINTS TO THE DIRECTORY IN YOUR THEME FOLDER THAT HAS FPDF.PHP
    require(FPDF_PATH.'fpdf.php');
    
    $posted_data = $submission->get_posted_data();
    // SAVE FORM FIELD DATA AS VARIABLES
    $name = $posted_data["your-name"];
    $email = $posted_data["your-email"];
    $subject = $posted_data["your-subject"];
    $message = $posted_data["your-message"];
    
    $pdf = new FPDF();
    $pdf->AddPage();
    $pdf->SetFont('Arial','B',16);
    $pdf->Write(5,$name . "\n\n" . $email . "\n\n" . $subject . "\n\n" . $message);
    $pdf->Output(FPDF_PATH.'test.pdf', 'F'); // OUTPUT THE NEW PDF INTO THE SAME DIRECTORY DEFINED ABOVE
    
    }
    }
    
    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'); // ATTACH THE NEW PDF THAT WAS SAVED ABOVE
    }
    return $components;
    }
Viewing 1 replies (of 1 total)

The topic ‘Convert form output to pdf attachment’ is closed to new replies.