Populating checkboxes with images - trim() warning

I’m getting the following warning (multiple times) when I try to populate checkboxes with images from a custom directory…

trim() expects parameter 1 to be string, array given in …/gravityforms/includes/fields/class-gf-field-checkbox.php on line 336

This doesn’t prevent the images from rendering correctly on the frontend, but I’d still like to fix the issue if possible. I’ve searched for two hours without finding any answers, so hoping someone can help pinpoint what’s causing the warning?..

add_filter( 'gform_pre_render_3', 'checkbox_images' );
add_filter( 'gform_pre_validation_3', 'checkbox_images' );
add_filter( 'gform_admin_pre_render_3', 'checkbox_images' );
add_filter( 'gform_pre_submission_filter_3', 'checkbox_images' );
function checkbox_images( $form ) {
	foreach( $form['fields'] as &$field )  {
 
        $field_id = 41;
        if ( $field->id != $field_id ) {
            continue;
        }
		
		$userid = get_current_user_id();
		$clientName = get_user_meta ($userid, 'client_name', true);
		$clientSlug = sanitize_title($clientName);
		$uploads = wp_upload_dir();		
		$clientDir = $uploads['basedir'].'/client-images/'.$clientSlug.'/';
		
		if( !file_exists ($clientDir) ){
			$imgFolder = 'placeholder-images';
		} else {
			$imgFolder = $clientSlug;
		}

		$imgDir = $uploads['basedir'].'/client-images/'.$imgFolder.'/';
		$imgUrl = $uploads['baseurl'].'/client-images/'.$imgFolder.'/';

		$images = array_diff(scandir($imgDir), array('..', '.'));

        $input_id = 1;
        foreach( $images as $image ) {
 
            //skipping index that are multiples of 10 (multiples of 10 create problems as the input IDs)
            if ( $input_id % 10 == 0 ) {
                $input_id++;
            }
 
			$choices[] = array('text'=>'<img src="'.$imgUrl.$image.'" class="checkbox-img" data-no-retina />','value'=>$image);
			$inputs[] = array('label'=>$image,'id'=>"{$field_id}.{$input_id}");
 
            $input_id++;
        }
        $field->choices = $choices;
        $field->inputs = $inputs;
     }
     return $form;
}

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