InsideDarkWeb.com

Set Default Value for Image Field contain Multiple Images

I’ve added a multiple image field to the user account that uses the multiupload_imagefield_widget and it works when I edit the account.

On the other hand, I have a custom module with a form that I would like to edit just this field (I have a submit handler to update the user data). I call user_load to display the data and I can see the data is there in the debugger, but no images are displayed on the form.

What do I have to do to make them show up?

Here’s my code:

$user_data = user_load($user->uid);
$form['my_imageGallery'] = array(
  '#type'             => 'image',
  '#title'            => t('Image Gallery'),
  '#default_value'    => isset($user_data->field_galeria) ? $user_data->field_galeria : null,
  '#upload_location'  => 'public://user_galleries/',
  '#upload_validators' => array('file_validate_extensions' => array('png jpg gif')),
);

Drupal Answers Asked by pglatz on November 11, 2021

1 Answers

One Answer

I think you need to use a managed_file form element.

$user_data = user_load($user->uid);
$form['my_imageGallery'] = array(
  '#type'             => 'managed_file',
  '#title'            => t('Image Gallery'),
  '#default_value'    => isset($user_data->field_galeria) ? $user_data->field_galeria : null,
  '#upload_location'  => 'public://user_galleries/',
  '#upload_validators' => array('file_validate_extensions' => array('png jpg gif')),
);

Answered by Chris Happy on November 11, 2021

Add your own answers!

Related Questions

Ask a Question

Get help from others!

© 2021 InsideDarkWeb.com. All rights reserved.