Multi-file upload Merge Tag?

Why is it so hard to get an unordered list of uploaded files from a Multi-file upload field? I went down a rabbit hole trying to figure out how to get the contents of a multi-file upload field into a place that a front-end user could see it.

I don’t understand why other fields are so easy to work with and this one is so difficult, especially because if you just view the entry on the backend, obviously something is generating that list…
The current multi-file upload field merge tag is mostly worthless. Who needs an unformatted list of urls?

I finally had to write a shortcode myself to accomplish the task.

function gravity_form_file_list_entry_shortcode( $atts ) {
    // Get the entry ID and field ID from the shortcode attributes.
    $entry_id = $atts['entry_id'];
    $field_id = $atts['field_id'];

    // Get the entry details.
    $entry = GFAPI::get_entry( $entry_id );

    // Check if the entry exists.
    if ( is_wp_error( $entry ) ) {
        return 'Entry not found.';
    }

    // Decode the JSON-encoded field values.
    $field_values = json_decode( rgar( $entry, $field_id ) );

    if ( is_array( $field_values ) && !empty( $field_values ) ) {
        // Output the list of files.
        $output = '<ul>';
        foreach ( $field_values as $file_url ) {
            $file_name = basename( $file_url );
            $output .= '<li><a href="' . esc_url( $file_url ) . '">' . esc_html( $file_name ) . '</a></li>';
        }
        $output .= '</ul>';

        // Return the output.
        return $output;
    } else {
        return 'No files uploaded for this field.';
    }
}

add_shortcode( 'gravity_form_file_list_entry', 'gravity_form_file_list_entry_shortcode' );

usage: [gravity_form_file_list_entry entry_id=“{id of entry}” field_id=“{id of multi-file-upload field}”]

Maybe I made this harder than it had to be? Maybe someone can correct me, but if not. This code might help someone down the road facing a similar situation.

Does this Gravity Wiz snippet do anything additional that you need?

No, I did try to use this only really works for uploading, not so much displaying the entry once it’s already been submitted.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.