• Resolved brandonwebfast

    (@brandonwebfast)


    // Add cf7 data to database
    function contactform7_before_send_mail( $form_to_DB ) {
    	
        // Set your db details
        $mydb = new wpdb('username','password','database','host');
    
        $form_to_DB = WPCF7_Submission::get_instance();
        if ( $form_to_DB ) 
            $formData = $form_to_DB->get_posted_data();
    	
    	// Set Variables
        $username = $formData['username'];
    	$companyname = $formData['company-name'];
    	$signfirst = $formData['sign-1'];
    	$dateofpurchase = $formData['date-of-purchase'];
    	$pdfFile = $formData['comments-on-electric-fence'];
    
    	// Insert into db Table
        $mydb->insert( 'TableName', array( 'Username' =>$username, 'CompanyName' =>$companyname, 'SignTest' =>$signfirst, 'DateTest' =>$dateofpurchase, 'Upload' =>$pdfFile ), array( '%s' ) );
    }
    remove_all_filters ('wpcf7_before_send_mail');
    add_action( 'wpcf7_before_send_mail', 'contactform7_before_send_mail' );

    Hi,

    I have been having a great time inserting data into the table that I created with your plugin. I just cant seem to insert an uploaded .pdf file from the CF7 form. It does go through to the table row and inserts the username, companyname, etc. although it does send through the pdf file, when I try to read it on the publisher or viewing the data on the table itself then in that row it just gives me this output ‘cd809a1cc070a22ff6deafd4a2ac02ac’

    I have tried varbinary, blob, largeblob and text.

    I really cant seem to get it to work so if you could kindly give me direction in the data designer what I should do to be able to store and view the file I would REALLY appreciate it!

    Kind Regards
    Brandon

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Passionate Programmer Peter

    (@peterschulznl)

    Hi Brandon,

    You are reading your pdf content from $formData (= $form_to_DB->get_posted_data()).
    Are you sure this is correct? Maybe use var_dump to check? Does it contain the file content? I would expect you to read it from $_FILES.

    I think you need to read the file content, store it in a variable and use the variable in your insert. Please be aware that this means you need to read the whole file into memory, so this will not work with large files that do not fit into memory.

    Here is some example code that might help a little:
    https://programmierfrage.com/items/wordpress-getting-images-from-db-stored-as-blob-data

    Best regards,
    Peter

    Thread Starter brandonwebfast

    (@brandonwebfast)

    Hi @peterschulznl

    Thank you for your response and have been working almost non stop to get this working.

    I did try your linked post but it just inserts it as text.

    I have changed to form data to $_FILES and it also hasn’t worked. I tried numerous ways of inserting the data as well trying to insert the path of where the file lays in the /wp-content/uploads/… but it just inserts the link as text and not as when you change the column type under manage > settings > column settings > column type – Attachments.

    When I change it to ‘Attachments’ column type then it doesnt insert anything into the table. It leaves it blank.

    I also tried with a ‘Hyperlink’ column type but yet it doesnt display anything. Even though I know there are path links in the field.

    We are also going to get the premium version of the plugin as we need the edit/delete functionality. Does this include you assisting on getting this to work?

    If there are any suggestions on how I can insert that link to do that same as the attachment column type in the mean while then I would GREATLY appreciate it!

    Kind Regards
    Brandon

    Thread Starter brandonwebfast

    (@brandonwebfast)

    So I think I found a way that might help. Is there any documentation in regards to inserting data using PHP in the field with a column type of hyperlink?

    As inserting it manually does work for me.

    https://ibb.co/myMbGKX

    Here is a linked image on the field that I want to insert into and this is the link I would like to use.

    https://websitedesignshop.co.uk/wp-content/uploads/2022/04/pdftestd2oc.pdf

    Plugin Author Passionate Programmer Peter

    (@peterschulznl)

    Hi Brandon,

    >>> So I think I found a way that might help. Is there any documentation in regards to inserting data using PHP in the field with a column type of hyperlink?

    You don’t need to! If you just change the table settings you can enter plain URLs. Here is the documentation:
    https://wpdataaccess.com/docs/documentation/data-explorer/table-settings/

    Please click on the first image on the documentation page and look for “Process hyperlink columns as”. If you select “Plain text” for the table you are working on, you can write plain URLs in that column.

    Does this help?
    Peter

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Store .PDF file in database table’ is closed to new replies.