How is it possible to add an image upload table in the code of a custom module in Drupal 7?

In other words, I want to add the "Images Table" (the one with drag-able rows) to a custom form I'm creating in my custom module. And I need all it's options too, like thumbnail, title and description fields for each uploaded image row plus the remove button, with the ability to limit the number of uploaded images of course.

What is the code to be used to achieve that?

Thanks for your time and help in advance.

1 Answer 1


Image upload fields and drag & drop tables are two separate elements that you can combine in your module by using a form callback function to declare your fields and a theme function to theme the upload fields in a drag & drop table.

D7 Form API provides an upload field named 'managed_file'. The documentation provides a clear example:

// Use the #managed_file FAPI element to upload an image file.
$form['image_example_image_fid'] = array(
  '#title' => t('Image'),
  '#type' => 'managed_file',
  '#description' => t('The uploaded image will be displayed on this page using the image style choosen below.'),
  '#default_value' => variable_get('image_example_image_fid', ''),
  '#upload_location' => 'public://image_example_images/',

Then you can have a look at the documentation to setup the field with your desired settings. This element does not have a #multiple setting. So you can either generate many fields, either add new fields using ajax as in cck in D6.

Finally you can check this documentation on how to use drupal_add_tabledrag();

  • Thanks, that really helped. But what about displaying an image thumbnail and extended fields in each row? Any ideas!? I found the following documentation, but don't know how to implement it yet.
    – Peter
    Jun 27, 2011 at 11:26
  • How is it possible to display the uploaded images in a table? That question isn't yet answered!
    – Peter
    Jun 28, 2011 at 15:07
  • 1
    You say you are working on a D7 website, the ImageField link you added is a D6 website. To display the thumbnail you should use the theme(). You can create a thumbnail preset through drupal backend. Then you can have a look at this thread drupal.org/node/958726#comment-3959604 Jun 29, 2011 at 13:49
  • To add more field to the table you should create a custom menu item using hook_menu() in your drupal site to which to attach a callback that generates a form element. Then you add the form element to your table. Jun 29, 2011 at 13:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.