CalderaWP / Caldera-Forms

Drag and drop, responsive WordPress form builder.
https://CalderaForms.com
GNU General Public License v2.0
187 stars 163 forks source link

Save Files on Server doesn't work #2323

Open andre-kornetzky opened 6 years ago

andre-kornetzky commented 6 years ago

Hello. I'm about to validate Caldera for our mission and found an error. It does not work that uploaded files are stored on the server (permanently).

I have the following environment:

the short debug line is: WordPress Version: 4.9.4PHP Version: 7.2.2MySQL Version: 5.7.21Caldera Forms Version: 1.5.9.1WP_DEBUG: 1

When I enter an entry now, most things work fine (mail is sent, database entry is created, ...). Only no file is available behind the link. For example: http://localhost:8080/wp-content/uploads/7e524d2b14b4db2883e4c8b422fa9937/pig.png

But there is no file or folder to find in uploads.

If I activate "Attach to Mailer" the file will be added to the mail. If I activate "Add to Media Library", the file is stored in the Media Library. If nothing is activated, the file is gone.

After reading the following article (https://calderaforms.com/doc/how-caldera-forms-file-attachments-uploads-work/), I created a child theme and added the lines to the functions.php.

<?php

add_action( 'wp_enqueue_scripts', 'form_theme_styles' );

function form_theme_styles() {
    wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' );
    wp_enqueue_style( 'form-theme', get_stylesheet_directory_uri() . '/style.css', array( 'parent-style' ), wp_get_theme()->get('Version') );
}

/** Wait until caldera_forms_core_init hook so we know all actions were added **/ 
add_action( 'caldera_forms_core_init', function() {
    //File delete is attempted first here, but if an email should send, the file isn't deleted//
    remove_action( 'caldera_forms_submit_complete', array( 'Caldera_Forms_Files', 'cleanup' ) );

    //If email is set to be used, we wait until email is sent to delete on these hooks:
    remove_action( 'caldera_forms_mailer_complete', array( 'Caldera_Forms_Files', 'delete_after_mail' ), 10, 3 );
    remove_action( 'caldera_forms_mailer_failed', array( 'Caldera_Forms_Files', 'delete_after_mail' ), 10, 3 );

    //Just in case of a never completed submission or some other issue, a CRON job is used to delete the file
    remove_all_actions( Caldera_Forms_Files::CRON_ACTION );

});

?>

But it did not help. There is no entry in the log file (debug.log). It just does not save the file on the server.

Side Note: I also tested Contact Form 7 and the upload works there without problems. Therefore, I do not believe that the cause of the error is the write permissions.

Thank you for your work.

Shelob9 commented 6 years ago

Thanks for using Caldera Forms.

I just tested and with this code in place, and a form that has a file field, set to attach to the mailer, but not to upload. It worked as expected: the file was still on the folder.

Are you sure that this code is running? I would put it in a plugin.

Please note, this is not a support channel. If you need immediate help with your site or help troubleshooting Caldera Forms on your site, please open a support ticket at https://CalderaForms.com/support

andre-kornetzky commented 6 years ago

I get the email (if enabled) - so I think the plugin works in general. The theme also works - tested by manipulating the CSS file and an echo output in the funtions.php. But if I add an echo command in the function "add_action ('caldera_forms_core_init', ...", this line will not be printed. Probably 'caldera_forms_core_init' is never called in the functions.php of a theme?

OK, with a plugin it works for me too. So I think that the following statement is wrong:

Technically you can add the custom code to your theme's functions.php, but then you will not be able to change your theme and keep these customizations.

https://calderaforms.com/doc/alternative-file-upload-directory/

Can you test it with a theme and confirm the bug?