0

I need to restrict the user to upload only the file extensions that i mentioned in the Allowed file extensions filed. It works properly. But in front-end, i need to add a comma separator for this format.

Actual - Allowed file types: ai aif avi bmp csv doc docx eps fla flv gif img.

Expected - Allowed file types: ai, aif, avi, bmp, csv, doc, docx, eps, fla, flv, gif, img

2 Answers 2

1

You are definitely allowed to separate file types by comma in the admin are

enter image description here

For user area, find the ID of the form (you can find this in the firebug) then

function YourTheme_form_alter(&$form, &$form_state, $form_id){
      if($form_id == "TheFormID"){
            kpr($form);  
      }
}

In this way you can find the form elements. get the Key of image field in the form array, if it is image then write

function YourTheme_form_alter(&$form, &$form_state, $form_id){
      if($form_id == "TheFormID"){
            $form['image']['#description'] = t('File types are comma separated')
      }
}

This is the general idea but a few modification might be needed

3
  • This is back-end (admin area). I need to add comma in front-end (where the user uploads their files).
    – drup
    Apr 13, 2015 at 7:02
  • I need to add comma separation here. [1]: i.stack.imgur.com/B41dP.png
    – drup
    Apr 13, 2015 at 10:22
  • My code does this, it finds the ID of the form and alters the description
    – M a m a D
    Apr 13, 2015 at 12:46
1

I used theme_file_upload_help hook.

 function bartik_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('Files must be less than !size.', array('!size' => '<strong>' . format_size($upload_validators ['file_validate_size'][0]) . '</strong>'));

 }

 $a = explode(" ", $upload_validators ['file_validate_extensions'][0] );
  if (isset($upload_validators ['file_validate_extensions'])) {

$descriptions [] = t('Allowed file types: !extensions.', array('!extensions' => '<strong>' . check_plain(implode(", ", $a)) . '</strong>'));

 }

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

}
0

Your Answer

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

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