File upload path with a form value

You can alter the path of the file uploads to contain a submitted form value. It’s only possible alter the part of the path after the WordPress uploads directory.

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

Add the following code to your theme functions.php file (or create a plugin for it). The example below will upload the file to folder wp-content/uploads/form-uploads/VALUE/ where VALUE is the submitted value.

123
4
56
add_filter('quform_upload_path_1', function ($path, Quform_Element_File $element, Quform_Form $form) {    $value = $form->getValueText('quform_1_3');    $value = sanitize_file_name($value);
 
    return "form-uploads/$value/";}, 10, 3);
add_filter('quform_upload_path_1', function ($path, Quform_Element_File $element, Quform_Form $form) {
    $value = $form->getValueText('quform_1_3');
    $value = sanitize_file_name($value);

    return "form-uploads/$value/";
}, 10, 3);
  • On line 1, replace the number 1 with the form ID
  • On line 2, replace 1_3 with the unique ID of the element that you want to use the value for in the path
  • On line 5 you can change the path to suit, it must end a forward slash
1
2
34
5
67
8
function my_override_upload_path($path, Quform_Element_File $element, Quform_Form $form
{
    $value = $form->getValueText('quform_1_3');    $value = sanitize_file_name($value);
 
    return "form-uploads/$value/";}
add_filter('quform_upload_path_1', 'my_override_upload_path', 10, 3);
function my_override_upload_path($path, Quform_Element_File $element, Quform_Form $form
{
    $value = $form->getValueText('quform_1_3');
    $value = sanitize_file_name($value);

    return "form-uploads/$value/";
}
add_filter('quform_upload_path_1', 'my_override_upload_path', 10, 3);
  • On line 3, replace 1_3 with the unique ID of the element that you want to use the value for in the path
  • On line 6 you can change the path to suit, it must end a forward slash
  • On line 8, replace the number 1 with the form ID
Be inspired. © 2024 ThemeCatcher Ltd. 20-22 Wenlock Road, London, England, N1 7GU | Company No. 08120384 | Built with React | Privacy Policy