• Resolved thetishbyte

    (@thetishbyte)


    Hello, I ran into the issue where files are getting saved to the website. I’m aware that I can set it to delete the files with the submissions after a certain amount of time, but unless we can set it to be less than a day, we’d rather not have files that could potentially be accessed publicly (we’ve had issues with this before). Setting it to not store submissions in the database makes the files stay in the website.
    Would it be possible to not have it save files to the website (or at least keep them for a short time). We don’t need it to link to the file in the notification emails since it can just be attached.

Viewing 13 replies - 1 through 13 (of 13 total)
  • Plugin Support Kris – WPMU DEV Support

    (@wpmudevsupport13)

    Hi @thetishbyte

    I hope you are doing good today.

    I pinged our Forminator Team and SLS Team is there any walkaround for this. We will post an update here as soon as more information is available.

    Kind Regards,
    Kris

    Plugin Support Kris – WPMU DEV Support

    (@wpmudevsupport13)

    Hi @thetishbyte

    Could you try this code as a mu-plugin:
    https://gist.github.com/wpmudev-sls/d569bddd49a34f6453a6f69cfee05aa4

    You can install this code as a mu-plugin following this guide:
    https://wpmudev.com/docs/using-wordpress/installing-wordpress-plugins/#installing-mu-plugins

    Kind Regards,
    Kris

    Thread Starter thetishbyte

    (@thetishbyte)

    Hello, this plugin does solve the issue!

    Thread Starter thetishbyte

    (@thetishbyte)

    Hi, I didn’t want to reopen this issue, but I ran into a particular issue with the file uploads/attachments (and assuming this mu-plugin). If I set more than one recipient (multiple notifications) in the Email Notifications to receive the uploaded files, it only attaches to the first one. My working theory is that it takes the uploaded file, attaches it to the first notification (or one of, it varies), deletes the uploaded file, proceeds to attach the missing file to the other notifications. If it runs the delete after all other email notifications, then it would work correctly. Again, just a theory.

    Using the mu-plugin and the test form below, it should be reproducible.

    {"type":"form","data":{"fields":[{"id":"email-1","element_id":"email-1","form_id":"wrapper-5363-3118","type":"email","options":[],"cols":"12","conditions":[],"wrapper_id":"wrapper-5363-3118","validation":"","placeholder":"E.g. [email protected]","field_label":"Email Address","required":"1"},{"id":"upload-1","element_id":"upload-1","form_id":"wrapper-1410-9195","type":"upload","options":[],"cols":"12","conditions":[],"wrapper_id":"wrapper-1410-9195","field_label":"Upload file","filetypes":["all-image","all-video","all-document","all-audio","all-archive","all-text","all-spreadsheet","all-interactive","jpg|jpeg|jpe","gif","png","bmp","tiff|tif","webp","ico","heic","asf|asx","wmv","wmx","wm","avi","divx","flv","mov|qt","mpeg|mpg|mpe","mp4|m4v","ogv","webm","mkv","3gp|3gpp","3g2|3gp2","txt|asc|c|cc|h|srt","csv","tsv","ics","rtx","css","htm|html","vtt","dfxp","mp3|m4a|m4b","aac","ra|ram","wav","ogg|oga","flac","mid|midi","wma","wax","mka","rtf","js","pdf","class","tar","zip","gz|gzip","rar","7z","psd","xcf","doc","pot|pps|ppt","wri","xla|xls|xlt|xlw","mdb","mpp","docx","docm","dotx","dotm","xlsx","xlsm","xlsb","xltx","xltm","xlam","pptx","pptm","ppsx","ppsm","potx","potm","ppam","sldx","sldm","onetoc|onetoc2|onetmp|onepkg","oxps","xps","odt","odp","ods","odg","odc","odb","odf","wp|wpd","key","numbers","pages","ttf","otf","eot","woff","svg","redux"],"file-type":"single","file-limit":"unlimited","upload-limit":"8","filesize":"MB","required":"1","use_as_attachment":"1","delete_uploaded_file":"1"}],"settings":{"pagination-header":"nav","paginationData":{"pagination-header-design":"show","pagination-header":"nav"},"formName":"test uploads","version":"1.15.12","form-border-style":"none","form-padding":"","form-border":"","fields-style":"open","validation":"on_submit","akismet-protection":"1","form-style":"default","enable-ajax":"true","autoclose":"true","submission-indicator":"show","indicator-label":"Submitting...","form-type":"default","submission-behaviour":"behaviour-thankyou","thankyou-message":"Thank you for contacting us, we will be in touch shortly.","submitData":{"custom-submit-text":"Send Message","custom-invalid-form-message":"Error: Your form is not valid, please fix the errors!"},"validation-inline":"1","form-expire":"no_expire","form-padding-top":"0","form-padding-right":"0","form-padding-bottom":"0","form-padding-left":"0","form-border-width":"0","form-border-radius":"0","cform-label-font-family":"Roboto","cform-label-custom-family":"","cform-label-font-size":"12","cform-label-font-weight":"bold","cform-title-font-family":"Roboto","cform-title-custom-family":"","cform-title-font-size":"45","cform-title-font-weight":"normal","cform-title-text-align":"left","cform-subtitle-font-family":"Roboto","cform-subtitle-custom-font":"","cform-subtitle-font-size":"18","cform-subtitle-font-weight":"normal","cform-subtitle-text-align":"left","cform-input-font-family":"Roboto","cform-input-custom-font":"","cform-input-font-size":"16","cform-input-font-weight":"normal","cform-radio-font-family":"Roboto","cform-radio-custom-font":"","cform-radio-font-size":"14","cform-radio-font-weight":"normal","cform-select-font-family":"Roboto","cform-select-custom-family":"","cform-select-font-size":"16","cform-select-font-weight":"normal","cform-multiselect-font-family":"Roboto","cform-multiselect-custom-font":"","cform-multiselect-font-size":"16","cform-multiselect-font-weight":"normal","cform-dropdown-font-family":"Roboto","cform-dropdown-custom-font":"","cform-dropdown-font-size":"16","cform-dropdown-font-weight":"normal","cform-calendar-font-family":"Roboto","cform-calendar-custom-font":"","cform-calendar-font-size":"13","cform-calendar-font-weight":"normal","cform-button-font-family":"Roboto","cform-button-custom-font":"","cform-button-font-size":"14","cform-button-font-weight":"500","cform-timeline-font-family":"Roboto","cform-timeline-custom-font":"","cform-timeline-font-size":"12","cform-timeline-font-weight":"normal","cform-pagination-font-family":"","cform-pagination-custom-font":"","cform-pagination-font-size":"16","cform-pagination-font-weight":"normal","payment_require_ssl":"","submission-file":"delete","store_submissions":"1","form_name":"test-uploads","form_status":"publish"},"client_id":null,"integration_conditions":[],"behaviors":[{"slug":"behavior-1234-4567","label":"","autoclose-time":"5","autoclose":"true","newtab":"sametab","thankyou-message":"Thank you for contacting us, we will be in touch shortly.","email-thankyou-message":"","manual-thankyou-message":"","submission-behaviour":"behaviour-thankyou","redirect-url":""}],"notifications":[{"slug":"notification-1234-4567","label":"test 1","email-recipients":"default","recipients":"{email-1}","email-subject":"test 1","email-editor":"<p>test 1<br \/>This message was sent from {site_url}.<\/p>","email-attachment":"true"},{"slug":"notification-3403-1750","email-subject":"test 2","label":"test 2","email-editor":"<p>test 2<\/p>","email-attachment":"true","recipients":"{email-1}","from-name":"","form-email":"","replyto-email":"","cc-email":"","bcc-email":"","conditions":[]},{"slug":"notification-3173-8249","email-subject":"test 3","label":"test 3","email-editor":"<p>test 3<\/p>","email-attachment":"true","recipients":"{email-1}"}]},"status":"publish","version":"1.15.12"}

    Plugin Support Nithin – WPMU DEV Support

    (@wpmudevsupport11)

    Hi @thetishbyte,

    I could notice what you meant, I’m checking with our developer to see if there is any workaround that could be shared regarding this.

    Will keep you posted once we get further feedback.

    Kind Regards,
    Nithin

    Plugin Support Patrick – WPMU DEV Support

    (@wpmudevsupport12)

    Hi @thetishbyte

    I hope you are doing well.

    Could you please try the following script?

    <?php
    /**
    * Plugin Name: [Forminator] - Attach upload file to email
    * Plugin URI: https://premium.wpmudev.org/
    * Description: Adds two new options in Uplaod's Edit Field popup under the Advanced tab. One option is for adding the uploaded file as an attachment. Second option is for deleting the file after upload
    * Author: Panos Lyrakis & Prashant Singh @ WPMUDEV
    * Author URI: https://premium.wpmudev.org/
    * License: GPLv2 or later
    */
    
    if ( ! defined( 'ABSPATH' ) ) {
        exit;
    }
    
    if ( ! class_exists( 'WPMUDEV_Frominator_Upload_Email_Attachment' ) ) {
        
        class WPMUDEV_Frominator_Upload_Email_Attachment {
    
            public $attachments                 = array();
            public $attachments_to_delete       = array();
            private static $_instance           = null;
           
            public static function get_instance() {
    
                if( is_null( self::$_instance ) ){
                    self::$_instance = new WPMUDEV_Frominator_Upload_Email_Attachment();
                }
                return self::$_instance;
                
            }
    
            private function __construct() {
    
                add_filter( 'wp_mail', array( $this, 'filter_email_args' ) );
                add_filter( 'forminator_field_upload_general_settings', array( $this, 'add_attachment_settings' ) );
    
                add_filter( 'forminator_custom_form_submit_field_data', array( $this, 'manage_field_data' ), 20, 2 );
                add_action( 'forminator_custom_form_mail_after_send_mail', array( $this, 'delete_uploaded_files' ) );
    
            }
    
            public function add_attachment_settings( $settings ) {
    
                $attachment_option = array(
                        'type'          => 'Toggle',
                        'label'         => 'Attach to email',
                        'name'          => 'use_as_attachment'
                    );
                $delete_upload_option = array(
                        'type'          => 'Toggle',
                        'label'         => 'Delete file after upload',
                        'name'          => 'delete_uploaded_file'
                    );
    
                array_push( $settings, $attachment_option, $delete_upload_option );
    
                return $settings;
    
            }
    
            public function manage_field_data( $data, $form_id ) {
    
                foreach ( $data as $key => $field_data ) {
    
                    if ( ! isset( $field_data['name'] ) ) {
                        continue;
                    }
    
                    $field = Forminator_API::get_form_field( $form_id, $field_data['name'] );
    
                    if ( is_wp_error( $field ) ) {
                        continue;
                    }
    
                    $field_type    = Forminator_Field::get_property( 'type', $field );
    
                    if ( 'upload' != $field_type ) {
                        continue;
                    }
    
                    if ( $file_path = $field_data[ 'value' ][ 'file' ][ 'file_path' ] ) {
                        
                        if ( Forminator_Field::get_property( 'use_as_attachment', $field ) ) { 
                            unset( $this->attachments );                  
                            $this->attachments[] = $file_path;
                        }
    
                        if ( Forminator_Field::get_property( 'delete_uploaded_file', $field ) ) {                    
                            $this->attachments_to_delete[] = $file_path;
                        }
    
                    }
    
                }
    
                return $data;
            }
    
            public function filter_email_args( $mail_args ) {
    
                if ( ! empty( $this->attachments ) ) {
                    $mail_args[ 'attachments' ] = $this->attachments;
                }
    
                return $mail_args;
            }
    
            public function delete_uploaded_files() {
                
                if ( ! empty( $this->attachments_to_delete ) ) {
                    foreach ( $this->attachments_to_delete as $file_path ) {
                        unlink( $file_path );
                    }
                }
            }
        }
    
        if ( ! function_exists( 'wpmudev_forminator_upload_email_attachment' ) ) {
    
            function wpmudev_forminator_upload_email_attachment() {
                return WPMUDEV_Frominator_Upload_Email_Attachment::get_instance();
            };
    
            add_action( 'plugins_loaded', 'wpmudev_forminator_upload_email_attachment', 10 );
        }
    
    }

    You can use it as a mu-plugin https://wpmudev.com/docs/using-wordpress/installing-wordpress-plugins/

    We suggest making a Full backup first or testing it on a Staging website.

    Let us know the result you got.
    Best Regards
    Patrick Freitas

    Thread Starter thetishbyte

    (@thetishbyte)

    Hi, sorry for the late response.
    Would this be in addition to the existing mu-plugin ([Forminator] – Attach upload file to email) or would it replace it?
    Thanks!

    Hello @thetishbyte !

    In this case you’ll need to replace the previous snippet. Please keep a backup though in case you need to revert it. Adding something after the .php extension will disable the old snippet and allow you to restore it back if needed.

    Kind regards,
    Pawel

    Thread Starter thetishbyte

    (@thetishbyte)

    That has worked, thank you very much!

    Thread Starter thetishbyte

    (@thetishbyte)

    Apologies again, the fix was working specifically for the testing form, but it seems that a different (more complex) form doesn’t like the fix at all (it isn’t attaching the uploaded file to any of the recipients). I’ve reverted in the meantime so that it can continue with at least one working for now.

    The problem form in question is attached here.
    Is there a way to see what it doesn’t work with the new fix?

    Hello @thetishbyte !

    Hope you’re doing well today!

    I was able to confirm that there’s something that’s not working with this form, however I wasn’t able to find the cause and a fix yet.

    I’ve forwarded the case to our Second Line Support team who will look at the form and the snippet closer and will see if we can provide a fix for you. We’ll update you here as soon as we hear back from them.

    Warm regards,
    Pawel

    Plugin Support Dimitris – WPMU DEV Support

    (@wpmudev-support6)

    Hello @thetishbyte

    Previously shared code works fine for single upload but now that you are using multifile upload, that’s why the issue came. Please replace the previous MU plugin with the following one and let us know how that goes. ??

    <?php
    /**
    * Plugin Name: [Forminator] - Attach upload file to email
    * Plugin URI: https://premium.wpmudev.org/
    * Description: Adds two new options in Uplaod's Edit Field popup under the Advanced tab. One option is for adding the uploaded file as an attachment. Second option is for deleting the file after upload
    * Author: Panos Lyrakis & Prashant Singh @ WPMUDEV
    * Author URI: https://premium.wpmudev.org/
    * License: GPLv2 or later
    */
    
    if ( ! defined( 'ABSPATH' ) ) {
        exit;
    }
    
    if ( ! class_exists( 'WPMUDEV_Frominator_Upload_Email_Attachment' ) ) {
        
        class WPMUDEV_Frominator_Upload_Email_Attachment {
    
            public $attachments                 = array();
            public $attachments_to_delete       = array();
            private static $_instance           = null;
           
            public static function get_instance() {
    
                if( is_null( self::$_instance ) ){
                    self::$_instance = new WPMUDEV_Frominator_Upload_Email_Attachment();
                }
                return self::$_instance;
                
            }
    
            private function __construct() {
    
                add_filter( 'wp_mail', array( $this, 'filter_email_args' ) );
                add_filter( 'forminator_field_upload_general_settings', array( $this, 'add_attachment_settings' ) );
    
                add_filter( 'forminator_custom_form_submit_field_data', array( $this, 'manage_field_data' ), 20, 2 );
                add_action( 'forminator_custom_form_mail_after_send_mail', array( $this, 'delete_uploaded_files' ) );
    
            }
    
            public function add_attachment_settings( $settings ) {
    
                $attachment_option = array(
                        'type'          => 'Toggle',
                        'label'         => 'Attach to email',
                        'name'          => 'use_as_attachment'
                    );
                $delete_upload_option = array(
                        'type'          => 'Toggle',
                        'label'         => 'Delete file after upload',
                        'name'          => 'delete_uploaded_file'
                    );
    
                array_push( $settings, $attachment_option, $delete_upload_option );
    
                return $settings;
    
            }
    
            public function manage_field_data( $data, $form_id ) {
    
                foreach ( $data as $key => $field_data ) {
    
                    if ( ! isset( $field_data['name'] ) ) {
                        continue;
                    }
    
                    $field = Forminator_API::get_form_field( $form_id, $field_data['name'] );
    
                    if ( is_wp_error( $field ) ) {
                        continue;
                    }
    
                    $field_type    = Forminator_Field::get_property( 'type', $field );
    
                    if ( 'upload' != $field_type ) {
                        continue;
                    }
                    if( !is_array( $field_data[ 'value' ][ 'file' ][ 'file_path' ] ) ){
                        if ( $file_path = $field_data[ 'value' ][ 'file' ][ 'file_path' ] ) {
                            
                            if ( Forminator_Field::get_property( 'use_as_attachment', $field ) ) { 
                                unset( $this->attachments );                  
                                $this->attachments[] = $file_path;
                            }
    
                            if ( Forminator_Field::get_property( 'delete_uploaded_file', $field ) ) {                    
                                $this->attachments_to_delete[] = $file_path;
                            }
    
                        }
                    } else {
                        unset( $this->attachments );
                        foreach( $field_data[ 'value' ][ 'file' ][ 'file_path' ] as $fi_k => $fi_val ){
    
                            if ( Forminator_Field::get_property( 'use_as_attachment', $field ) ) {   
                                $this->attachments[] = $fi_val;
                            }
    
                            if ( Forminator_Field::get_property( 'delete_uploaded_file', $field ) ) {                    
                                $this->attachments_to_delete[] = $fi_val;
                            }
    
                        }
                    }
    
                }
    
                return $data;
            }
    
            public function filter_email_args( $mail_args ) {
    
                if ( ! empty( $this->attachments ) ) {
                    $mail_args[ 'attachments' ] = $this->attachments;
                }
    
                return $mail_args;
            }
    
            public function delete_uploaded_files() {
                
                if ( ! empty( $this->attachments_to_delete ) ) {
                    foreach ( $this->attachments_to_delete as $file_path ) {
                        unlink( $file_path );
                    }
                }
            }
        }
    
        if ( ! function_exists( 'wpmudev_forminator_upload_email_attachment' ) ) {
    
            function wpmudev_forminator_upload_email_attachment() {
                return WPMUDEV_Frominator_Upload_Email_Attachment::get_instance();
            };
    
            add_action( 'plugins_loaded', 'wpmudev_forminator_upload_email_attachment', 10 );
        }
    
    }

    Take care,
    Dimitris

    Thread Starter thetishbyte

    (@thetishbyte)

    This fix works, thank you!

Viewing 13 replies - 1 through 13 (of 13 total)
  • The topic ‘“Disable store submissions in my database” still uploads images to website.’ is closed to new replies.