summaryrefslogtreecommitdiff
path: root/httemplate/elements/form-file_upload.html
blob: 4ab70ad9c6716dedeb7d08ff41e59818b38c3ea4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
<%doc>

Example:

  <% include( '/elements/form-file_upload.html',

                'name'      => 'form_name',
                'action'    => 'process/target.cgi', #progress-init target
                'fields'    => [ 'other', 'form', 'fields' ],
                'num_files' => 1, #or more

                'url' => $url
                #AND/OR
                'message' => 'Message',

                #optional
                'key' => 'unique_key', #for using more than once on a page
            )

% #... 

% # num_files=>1
  include( '/elements/file-upload.html',
             'field'    => 'element',
             'label'    => 'Label',
         )

% # OR

% # num_files=>2 # or more
  include( '/elements/file-upload.html',
             'field'    => [ 'element', 'element2', ], #etc.
             'label'    => [ 'Label',   'Label2',   ], #etc.
         )


%>

</%doc>

<% include( '/elements/progress-init.html',
              $opt{name},
              $opt{fields},
              $opt{action},
              $msg_or_url,
              $opt{key},
          )
%>

<SCRIPT>

  function <% $opt{key} %>gotUploaded(success, message) {

    var uploaded = document.getElementById('uploaded_files');
    var a = uploaded.value.split(',');
    if (success && uploaded.value.split(',').length == <% $opt{num_files} %>){
      process(); 
    }else{
      var p = document.getElementById('uploadError');
      p.innerHTML='<FONT SIZE="+1" COLOR="#ff0000">Error: '+message+'</FONT><BR><BR>';
      p.style='display:visible';
      return false;
    }
    
  }

</SCRIPT>

<div style="display:none:" id="uploadError"></div>

<FORM NAME     = "<% $opt{name} %>"
      ACTION   = "<% $fsurl %>misc/file-upload.html"
      METHOD   = "POST"
      ENCTYPE  = "multipart/form-data"
      onSubmit = "return doUpload(this, <% $opt{key} %>gotUploaded)"
>

<%init>

#my( $formname, $fields, $action, $url_or_message, $key ) = @_;
my %opt = ref($_[0]) ? %{ $_[0] } : @_;

my $key = exists $opt{key} ? $opt{key} : '';

push @{ $opt{fields} }, 'uploaded_files';

my $msg_or_url = $opt{message}
                   ? { 'message' => $opt{message},
                       'url'     => $opt{url},
                     }
                   : $opt{url};

</%init>