Drupal file_validate_extensions для расширения вложения файла с использованием hook_form_alter
Я построил модуль, который изменяет форму с помощью функции под названием form_mods_form_alter. Я хочу разрешить только типы файлов jpg, jpeg, png. То, что я имею, не проверяет. Это позволяет GIF, и я не хочу, чтобы GIF.
<?php
function form_mods_form_alter($form, $form_state, $form_id) {
// Ad form
if($form_id == 'ad_node_form'){
$form['attachments']['wrapper']['new']['upload']['#description'] = 'BBGI test The maximum upload size is 1 MB. Only files with the following extensions may be uploaded: jpg jpeg png.';
$form['attachments']['wrapper']['new']['upload']['#ahah']['#upload_validators']['file_validate_extensions'][0] = 'png jpg jpeg';
}
}
?>
Вот что я получаю с помощью print_r($form);
[attachments] => Array
(
[#type] => fieldset
[#access] => 1
[#title] => File attachments
[#collapsible] => 1
[#collapsed] => 1
[#description] => Changes made to the attachments are not permanent until you save this post. The first "listed" file will be included in RSS feeds.
[#prefix] =>
[#suffix] =>
[#weight] => 30
[wrapper] => Array
(
[#prefix] =>
[#suffix] =>
[#theme] => upload_form_new
[#cache] => 1
[new] => Array
(
[#weight] => 10
[upload] => Array
(
[#type] => file
[#title] => Attach new file
[#size] => 40
[#description] => BBGI test The maximum upload size is 1 MB. Only files with the following extensions may be uploaded: jpg jpeg png.
[#ahah] => Array
(
[#upload_validators] => Array
(
[file_validate_extensions] => Array
(
[0] => png jpg jpeg
)
)
)
)
[attach] => Array
(
[#type] => submit
[#value] => Attach
[#name] => attach
[#ahah] => Array
(
[path] => upload/js
[wrapper] => attach-wrapper
[progress] => Array
(
[type] => bar
[message] => Please wait...
)
[#upload_validators] => Array
(
[file_validate_extensions] => Array
(
[0] => png jpg jpeg
)
)
)
[#submit] => Array
(
[0] => node_form_submit_build_node
)
)
)
)
)
1 ответ
Валидаторы загрузки должны идти на элемент, а не на #ahah
имущество. Попробуй это:
$form['attachments']['wrapper']['new']['upload']['#upload_validators']['file_validate_extensions'][0] = 'png jpg jpeg';