Alternative File Uploaders For Caldera Forms

Caldera Forms Banner

This is a developer-focused document. If you want a “just works” solution, please consider the 3rd-party add-on FileTrip.

By default Caldera Forms uploads files from file and advanced file fields to your uploads directory. In version 1.4.4 or later, you can use the “caldera_forms_file_upload_handler” filter to use an alternative upload handler of your own design. The default upload handler is Caldera_Forms_Files::upload(), which uses wp_handle_upload() to upload files to your server.

Note, that if you just wish to change the file path, relative to the uploads directory, it is easier to use caldera_forms_upload_directory filter.

In this example, a custom handler is used to upload files via SFTP:

To make this example work, you must install the ssh2 PHP extension. Also, make sure to set the three constants it uses for SFTP credentials.

This example is shown to illustrate how this system works.  The caldera_forms_file_upload_handler filter is used specify that file fields should attempt to upload files using the “my_custom_uploader” function. This function is then passed each file being uploaded. The variable $field is a key of the $_FIELDS super global, after it is validated.


Where Does This Code Go?

When using WordPress hooks to customize Caldera Forms or other plugins you should not modify the plugin files, or you will lose your changes when you update the plugin. Instead you should create a small plugin to hold the custom code. It's easy, learn how here.

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.

Learn More