2011-11-16 2 views
0

form_mods_form_alter라는 함수로 폼을 변경하는 모듈을 만들었습니다. jpg, jpeg, png 파일 형식 만 허용하고 싶습니다. 내가 가지고있는 것은 검증이 안된다. 그것은 gif를 허용하고 gif를 허용하고 싶지 않습니다.hookup_form_alter를 사용한 파일 첨부 확장을위한 Drupal file_validate_extensions

<?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 
             ) 

           ) 

         ) 

       ) 

     ) 
+0

여기서 공통 함정 http://api.drupal.org/api/drupal/includes--file ([file_validate_extensions]로서 관리 (사용자 1) 계정만을 테스트하는 것이다. inc/function/file_validate_extensions/6)은 해당 사용자의 유효성 검사를 건너 뜁니다. –

답변

0

업로드 유효성 검사기는 #ahah 속성이 아니라 요소로 이동해야합니다. 이 시도 :

$form['attachments']['wrapper']['new']['upload']['#upload_validators']['file_validate_extensions'][0] = 'png jpg jpeg'; 
+0

나는 그것을 시험해 보았고 여전히 gif를 업로드하여 목록에 올릴 수있다. – EricP