Hi All,
I’m currently using the following borrowed code to create a unique folder in Dropbox for each submission. The problem is that I initially set this up to work with a required ‘first/middle/last’ name field. I’ve now had to make the middle optional, and the process fails when the middle is left empty.
Outside of removing the middle name, is there a way to leave it in tact and adjust for null values? I’m obviously not a PHP guru…
// 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 field used to collect the client name
//$uploads_field_id = '2';
//Get full Name from form
$name = rgar( $entry, '423.6' ).', '. rgar( $entry, '423.3' ).' '. rgar( $entry, '423.4' );
//Set dir name
$client_dir = $name;
// Replace spaces with a hyphen and remove all non-alphanumerics
//$client_dir = str_replace( ' ', '-', rgar( $entry, $uploads_field_id ) );
//$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 = '8';
add_filter( 'gform_dropbox_folder_path_' . $uploads_form_id, 'upload_to_client_dir', 10, 5 );