Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * alter form field element:.
- *
- * Implements hook_FORM_alter
- */
- function my_module_form_alter(&$form, &$form_state, $form_id) {
- $upload_validators = array(
- 'my_module_file_validate_extensions_blacklist' => ['jpg jpeg gif png mp4']
- );
- $form['your_file_field_element']['#upload_validators'] = $upload_validators;
- }
- function my_module_file_validate_extensions_blacklist(stdClass $file, $extensions) {
- $errors = array();
- $regex = '/\.(' . preg_replace('/ +/', '|', preg_quote($extensions)) . ')$/i';
- if (preg_match($regex, $file->filename)) {
- $errors[] = t('files with the following extensions are not allowed: %files-allowed.', array(
- '%files-allowed' => $extensions,
- ));
- }
- return $errors
- }
Add Comment
Please, Sign In to add comment