Snippets

nvisionsolution Client Uploads Directory by First Name Last Name Example

Created by Kyle Street last modified
// Organize the uploads in our uploads directory by client_name
function upload_to_client_dir( $folder_path, $form, $field_id, $entry, $feed ) {

    // ID of the fields used to collect the client name
    $firstname_field_id = '2';
    $lastname_field_id = '3';

    // Replace spaces with a hyphen and remove all non-alphanumerics
    $firstname = str_replace( ' ', '-', rgar( $entry, $firstname_field_id ) );
    $lastname = str_replace( ' ', '-', rgar( $entry, $lastname_field_id ) );
    $client_dir = $firstname . '-' . $lastname;
    $client_dir = preg_replace( '/[^A-Za-z0-9\-]/', '', $client_dir );

    // Create a folder for the client to add their uploads to
    return $folder_path . '/' . $client_dir;

}

// Update the dropbox upload path on a specific form (uploads form)
$uploads_form_id = '9';
add_filter( 'gform_dropbox_folder_path_' . $uploads_form_id, 'upload_to_client_dir', 10, 5 );

Comments (0)

HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.