0

On my website, members can pay for 3 different offers (Gold, Silver, Bronze). I would like to limit the number of pictures a member can upload, depending on the offer he picked.

I'm using Drupal's user_form and add an "Imagefield" field, with illimited upload. Offers are 3 taxonomy terms, and all contain a field with the max number of images allowed.

I'm able to get the amount of images allowed, from the taxonomy term, but how would i go about applying that limit to the imagefield?

Thanks a lot!

1 Answer 1

2

This will need customising to your specific situation, but the basic idea is to add a validation handler to the node form and perform a check in there, e.g.

function MYMODULE_form_alter(&$form, &$form_state, $form_id) {
  if ($form_id == 'the_form_id') {
    $form['#validate'][] = 'MYMODULE_images_validate_limit';
  }
}

function MYMODULE_images_validate_limit($form, &$form_state) {
  $images_submitted = count($form_state['values']['field_image'][LANGUAGE_NONE]);

  if ($images_submitted > function_to_get_limit()) {
    form_set_error('field_image', t('Too many images'));
  }
}

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.