2

I need to limit the number of upload files programmatically because the max number of files is 10 or unlimited and I need 14 upload files. Is it possible? I found the Upload max files module, but my question is if it is possible, programmatically.

I have installed Drupal 6.

2
  • What do you mean by "programmatically"? If I understand your question correctly, why would you like to write a custom code instead of reusing existing contrib module? What Drupal core version are you using?
    – LLub
    Commented Sep 27, 2011 at 22:01
  • My version of Drupal is 6. This module allows limit of number of upload per node. If in my content type I have two fields: photos and images. Photos field have 12 upload files and Images field have 15 upload files. The module allows put of limit 25 upload files but not allows restrict the number of upload files for each field. I'm sorry my english.
    – cabita
    Commented Sep 27, 2011 at 22:49

2 Answers 2

1

The patch reported in Add a custom 'number of values' for 'multiple/ multi-value' field. (e.g. nodereference, image field) can be useful to solve your requirement. (It has been tested with Drupal 6.20.)

1

I assume you use filefield module for attachment, if so, use this:

/**
 * Implementation of hook_form_alter().
 */
function YOURMODULENAME_form_alter(&$form, $form_state, $form_id) {
  if ($form_id == 'content_field_edit_form') {
    $form['field']['multiple']['#options'] = array(1 => t('Unlimited'), 0 => 1) + drupal_map_assoc(range(2, 14));
  }
}
9
  • I put this code but I can't see any changes. I put the name of field: field_images in 'field'.
    – cabita
    Commented Sep 27, 2011 at 23:17
  • Edit your field.
    – Nikit
    Commented Sep 27, 2011 at 23:51
  • I edited the field and I can't see any changes. Thanks for your help.
    – cabita
    Commented Sep 28, 2011 at 1:42
  • Let's do next: add drupal_set_message($form_id); above row: if ($form_id ==)... Then refresh field editing, what value it's show?
    – Nikit
    Commented Sep 28, 2011 at 4:02
  • I put: $form_id == 'story_edit_form' field == field_images YOUR MODULE == mymodule. Thank you very much for your help.
    – cabita
    Commented Sep 28, 2011 at 11:11

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.