1

The company I work for uses Drupal Webform to collect information regarding it's customers. At the very end of the webform, we have a file component with a size maximum of 64 MB. I was tasked with removing the description under the upload.

Description Image

Just to clarify, I don't want to remove the max size, just the text that says what the max size is.

2
  • Are want to change in all website or on particular webform?
    – CodeNext
    Aug 8, 2016 at 18:39
  • are you using D7 or D8?
    – CodeNext
    Aug 8, 2016 at 19:48

2 Answers 2

1

You need to add to your css file this style:

div.field-widget-file-generic p.help-block{
    display: none;
}
1

I am not sure which Drupal version are you using, as you have not provided. But if I use common sense, it should be D7, as webform module does not have stable D8 version.

Since you want the 64MB, it has to be done programmatically as that number comes from the code, so if you change tomorrow to 32MB, it needs to change accordingly, and display on that?

This we can do the by overriding the themeable output, You need to use function theme_file_upload_help()

Copy and paste that following code in your theme's template.php file, change the YourThemeName with your theme name. save and clear cache.

function YourThemeName_file_upload_help($variables) {
  $description = $variables['description'];
  $upload_validators = $variables['upload_validators'];

  $descriptions = array();

  if (strlen($description)) {
    $descriptions[] = $description;
  }
  if (isset($upload_validators['file_validate_size'])) {
    $descriptions[] = t('!size.', array('!size' => '<strong>' . format_size($upload_validators['file_validate_size'][0]) . '</strong>'));
  }
  if (isset($upload_validators['file_validate_extensions'])) {
    $descriptions[] = t('Allowed file types: !extensions.', array('!extensions' => '<strong>' . check_plain($upload_validators['file_validate_extensions'][0]) . '</strong>'));
  }
  if (isset($upload_validators['file_validate_image_resolution'])) {
    $max = $upload_validators['file_validate_image_resolution'][0];
    $min = $upload_validators['file_validate_image_resolution'][1];
    if ($min && $max && $min == $max) {
      $descriptions[] = t('Images must be exactly !size pixels.', array('!size' => '<strong>' . $max . '</strong>'));
    }
    elseif ($min && $max) {
      $descriptions[] = t('Images must be between !min and !max pixels.', array('!min' => '<strong>' . $min . '</strong>', '!max' => '<strong>' . $max . '</strong>'));
    }
    elseif ($min) {
      $descriptions[] = t('Images must be larger than !min pixels.', array('!min' => '<strong>' . $min . '</strong>'));
    }
    elseif ($max) {
      $descriptions[] = t('Images must be smaller than !max pixels.', array('!max' => '<strong>' . $max . '</strong>'));
    }
  }

  return implode('<br />', $descriptions);
}

Image out-put:

enter image description here



Now this will remove Files must be less than part from entire web-site.

If you want to apply this change only to that particular webform you need to replace the following code in above code,

if (isset($upload_validators['file_validate_size'])) {
    $descriptions[] = t('!size.', array('!size' => '<strong>' . format_size($upload_validators['file_validate_size'][0]) . '</strong>'));
}

With,

if (isset($upload_validators['file_validate_size'])) {
      if('webform_ID'){
    $descriptions[] = t('!size.', array('!size' => '<strong>' . format_size($upload_validators['file_validate_size'][0]) . '</strong>'));
 }
}

Note:Change the 'webform_ID' with your webform's ID.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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