-2

I have a form created in CF7 with a signature field. I am also using CFDB. Rather than do the usual submit, I would like to capture the form as an image in a pdf and insert it into CFDB in a BLOB. I do not need to extract the fields data. I just need the image of the completed form and signature. It is important that it is saved to CFDB as a BLOB.

  1. Is there already a plugin that will do this (submit cf7 form to cfdb as pdf/BLOB)?
  2. If not, how can I get this done? What may be the steps?

WHAT I KNOW:

For a file submission CFDB requires three lines inserted into the database table wp_cf7dbplugin_submits with the following variables: submit_time, form_name, field_name, field_value, field_order, file

Line 1 submit_time = the unix time stamp for the submission (e.g. 1458238222.5717), form_name = the name of the form, field_name = Optional discription, field_value = the full name and extention of the file (e.g. card.pdf), field_order = 0 (a reference to the fields number in the form 0 = 1), file = contents (the BLOB)

Line 2 submit_time = the unix time stamp for the submission (e.g. 1458238222.5717), form_name = the name of the form, field_name = The words: "Submitted Login", field_value = The WP user name for the submission, field_order = 9999 (always 9999), file = NULL

Line 3 submit_time = the unix time stamp for the submission (e.g. 1458238222.5717), form_name = the name of the form, field_name = The words: "Submitted From", field_value = The IP address of the submission, field_order = 10000 (always 10000), file = NULL

WHAT I THINK I NEED TO FIGURE OUT

  1. How to use a submit button to capture the screen and make it into a file saved to the cf7 upload directory as a pdf temporarily

  2. How to take that pdf and translate it into a blob to insert into the CFDB database in WP. I am ok with he php to insert into the database but I am not sure how to translate the pdf into a BLOB.

The final step would be to attach the pdf to an email to send the client and delete it from the upload folder. I think this will be easy to figure out so I mostly need help with steps 1 and 2. Any tips would be appreciated.

closed as off-topic by Howdy_McGee Feb 1 '17 at 16:04

This question appears to be off-topic. The users who voted to close gave this specific reason:

If this question can be reworded to fit the rules in the help center, please edit the question.

0

What I have learned is that the screen shot method is not really possible. So what I have done is used a method prescribed here using FPDF: https://wordpress.org/support/topic/convert-pdf-file

The last post is most instructive. The problem with this method is that it is not conditional regarding the form and so some if statements needed to be added for that. Also I am using the CF7 Signature add on and so needed a method for handling that image. I have also included a method for translating the PDF into a BLOB and importing it into the DFDB database:

function wpcf7_update_email_body($contact_form) {

        if ( $contact_form->id == 77 ) { //Number of the page for the form you are sending a PDF on.
        $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"];
            $signature = $posted_data["signature-113"];

            $pdf = new FPDF();
            $pdf->AddPage();
            $pdf->SetFont('Arial','B',16);
            $pdf->Write(5,$name . "\n\n" . $email . "\n\n" . $subject . "\n\n" . $message . "\n\n");
            $pdf->Image($signature,60,30,90,0,'PNG');  // The signiture file image
            $pdf->Output(FPDF_PATH.'test.pdf', 'F'); // OUTPUT THE NEW PDF INTO THE SAME DIRECTORY DEFINED ABOVE
        }
    }   
}
add_action('wpcf7_before_send_mail', 'wpcf7_update_email_body');


function mycustom_wpcf7_mail_components($components = null, $form = null){
    global $wpdb;
    $current_user = wp_get_current_user();
    $username = $current_user->user_login;
    $file_id = array_sum(explode(' ', microtime()));        

    if ($form->id == 77) {  //Number of the CF7 form (not the page id) you are sending a PDF on.

        $form_id = $form->id;
        $post = get_post($form_id);
        $formtitle = $post->post_title;
        $ip = getenv("REMOTE_ADDR");

        if (empty($components['attachments'])) {
        $filename = 'test.pdf';  // the full name and extention of the file as in the $pdf->Output variable above
        $filepath = FPDF_PATH .$filename;
        $components['attachments'] = $filepath; // ATTACH THE NEW PDF THAT WAS SAVED ABOVE  

        // Insert file into CFDB -- Get file contents.
        $tmpfile = fopen($filepath, "r");
        $contents = fread($tmpfile, filesize($filepath));

        // Insert the rows into CFDB.
        $wpdb->insert(wp_cf7dbplugin_submits, array(
            'submit_time'   => $file_id,
            'form_name'     => $formtitle,
            'field_name'    => '', // Optional description
            'field_value'   => $filename,
            'field_order'   => 0,
            'file'          => $contents, //the binary contents of the file
        ), array('%f', '%s', '%s', '%s',  '%d', '%s'));

        $wpdb->insert(wp_cf7dbplugin_submits, array(
            'submit_time'   => $file_id,
            'form_name'     => $formtitle,
            'field_name'    => 'Submitted Login', 
            'field_value'   => $username,
            'field_order'   => 9999,
            'file'          => NULL, 
        ), array('%f', '%s', '%s', '%s',  '%d', '%s'));

        $wpdb->insert(wp_cf7dbplugin_submits, array(
            'submit_time'   => $file_id,
            'form_name'     => $formtitle,
            'field_name'    => 'Submitted From', 
            'field_value'   => $ip,
            'field_order'   => 10000,
            'file'          => NULL,
        ), array('%f', '%s', '%s', '%s',  '%d', '%s'));     

        }
        return $components;
    } else {
        return $components;
    }
}
add_filter( 'wpcf7_mail_components', 'mycustom_wpcf7_mail_components',10,3 );

This all works great. Formatting and so forth is all explained in the FPDF website.

Not the answer you're looking for? Browse other questions tagged or ask your own question.