Modify the file upload path

This documentation page is for Quform version 1 and may not be applicable for Quform 2 click here to visit the documentation for Quform 2.

You can alter the path of the file uploads to contain submitted form data. It’s only possible just now to alter the part of the path after the WP uploads directory. In this example I will make the files upload into a directory named after the submitted name of the user.

Step 1

You will need the unique ID of the form, see Finding the form ID.

Step 2

In this example we’ll need to add an Single Line Text element to the form and get the unique element ID, see Finding the unique element ID.

Step 3

Add the following code to the wp-content/themes/YOUR_THEME/functions.php file (or create a plugin for it).

Note: this will apply to all File Upload fields in the form

In this example we’ll change the upload folder to [YOUR_WP_UPLOADS_DIRECTORY]/artists/[the submitted name]/.

1
2
34
5
67
8
function my_override_upload_path($path, $element)
{
    $name = $element->getForm()->getValue('iphorm_1_1');    $name = sanitize_file_name($name);
 
    return "artists/$name/";}
add_filter('iphorm_upload_path_1', 'my_override_upload_path', 10, 2);
function my_override_upload_path($path, $element)
{
    $name = $element->getForm()->getValue('iphorm_1_1');
    $name = sanitize_file_name($name);

    return "artists/$name/";
}
add_filter('iphorm_upload_path_1', 'my_override_upload_path', 10, 2);

Modify the highlighted lines to suit your form setup.

  • On line 3, change iphorm_1_1 to the unique ID of your Single Line Text element obtained in Step 2
  • On line 6, change artists/ to the any part you want before the name, or you can remove it
  • On line 8, change the number 1 to the form ID obtained in Step 1
Be inspired. © 2024 ThemeCatcher Ltd. 20-22 Wenlock Road, London, England, N1 7GU | Company No. 08120384 | Built with React | Privacy Policy