I want to add an add more button to an element in Drupal form (using Drupal Form API). Should I make it with javascript (append a new element) and check for $_POST in submission or is there another solution in Drupal API.

This is my code for that field, I want users to be able to upload more than one image:

$form['product'] = array(
  '#title' => t('product'),
  '#type' => 'managed_file',
  '#required' => TRUE,
  '#default_value' => variable_get('product', ''),
  '#upload_location' => 'public://',
  '#upload_validators' => array(
    'file_validate_extensions' => array('gif png jpg jpeg'),
    'file_validate_size' => array(0.6*1024*1024),
  • Depending on what you're trying to do, there are several options. By "add more" do you mean to allow the user to add another value to a field (for example, to upload more than one file per Webform submission)?
    – beth
    Jun 25, 2012 at 15:59
  • It looks like you want to use "Number of value:" option. it comes by default and you can find it in the configuration page of your field. Jun 25, 2012 at 16:10
  • @beth as you said to upload more than file using form api
    – Ahmed
    Jun 25, 2012 at 18:15
  • @SydBarrett I want to make a form using form Api not a cck
    – Ahmed
    Jun 25, 2012 at 18:16

3 Answers 3


Use Drupal's AJAX Form functionality to add elements to a form from the client.

If you try to update a Drupal form with JavaScript on the client side, it will not be submitted correctly. Drupal knows what was in the form when it was sent to the client, and expects that same structure to be sent back. Therefore, you need to use AJAX to tell Drupal the form is updated (with more fields, etc.).


You can allow multiple file uploads per field with the multiupload filefield widget module and if you need image support, extend it with the multiupload imagefield widget as well.


For your specific need to do multiple uploading of images another option would be to use the media gallery module (which requires media module).

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.