質問編集履歴
4
抜粋コードを確認できるようになりました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -316,8 +316,6 @@
|
|
316
316
|
|
317
317
|
}
|
318
318
|
|
319
|
-
print "HTMLにかけるように変更";
|
320
|
-
|
321
319
|
foreach (@item_names) {
|
322
320
|
|
323
321
|
my $name = conv_html($item_disp{$_});
|
3
動くコードに編集しました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -46,12 +46,10 @@
|
|
46
46
|
|
47
47
|
コード
|
48
48
|
|
49
|
-
|
49
|
+
#!/usr/bin/perl
|
50
50
|
|
51
51
|
use strict;
|
52
52
|
|
53
|
-
|
54
|
-
|
55
53
|
use Encode;
|
56
54
|
|
57
55
|
use Encode::Guess;
|
@@ -62,9 +60,11 @@
|
|
62
60
|
|
63
61
|
use CGI;
|
64
62
|
|
63
|
+
use utf8;
|
64
|
+
|
65
65
|
my $cgi = new CGI;
|
66
66
|
|
67
|
-
require 'mimew.pl';
|
67
|
+
require 'mimew.pl'; # jcode($subject)->mime_encode が動かないとき
|
68
68
|
|
69
69
|
#エラーメッセージをブラウザに表示
|
70
70
|
|
@@ -72,105 +72,221 @@
|
|
72
72
|
|
73
73
|
use Data::Dumper;
|
74
74
|
|
75
|
+
###################################
|
76
|
+
|
77
|
+
print "Content-Type: text/html; charset=utf-8\n\n";
|
78
|
+
|
79
|
+
# 項目名
|
80
|
+
|
81
|
+
my @item_names = ();
|
82
|
+
|
83
|
+
# 項目の日本語表示名
|
84
|
+
|
85
|
+
my %item_disp = ();
|
86
|
+
|
87
|
+
# 項目の値
|
88
|
+
|
89
|
+
my %item_value = ();
|
90
|
+
|
91
|
+
# 項目の必須有無
|
92
|
+
|
93
|
+
my %item_need = ();
|
94
|
+
|
95
|
+
# フォームパラメータ
|
96
|
+
|
97
|
+
my %fm_param = ();
|
98
|
+
|
99
|
+
my $cgi_url = $cgi->url(); # このCGIのURL
|
100
|
+
|
101
|
+
|
102
|
+
|
103
|
+
#######################################################################
|
104
|
+
|
105
|
+
# 入力文字コード判定
|
106
|
+
|
107
|
+
#######################################################################
|
108
|
+
|
109
|
+
my $input_value = '';
|
110
|
+
|
111
|
+
my $name;
|
112
|
+
|
113
|
+
my $value;
|
114
|
+
|
115
|
+
my @values;
|
116
|
+
|
117
|
+
foreach $name ($cgi->param) {
|
118
|
+
|
119
|
+
if ($name !~ /^submit$/i) { # 項目('submit'は除く)
|
120
|
+
|
121
|
+
@values = $cgi->param($name);
|
122
|
+
|
123
|
+
$value = join(',', @values);
|
124
|
+
|
125
|
+
if($cgi->param('fm_command') eq 'confsend') { # 確認フォームからのときデコード
|
126
|
+
|
127
|
+
$value = pack_param($value);
|
128
|
+
|
129
|
+
}
|
130
|
+
|
131
|
+
$input_value .= $value;
|
132
|
+
|
133
|
+
}
|
134
|
+
|
135
|
+
}
|
136
|
+
|
137
|
+
#エラーメッセージ配列
|
138
|
+
|
139
|
+
my @err_namelist = ();
|
140
|
+
|
141
|
+
|
142
|
+
|
143
|
+
#送信データがなければエラーとする
|
144
|
+
|
145
|
+
if (0 == length($input_value)) {
|
146
|
+
|
147
|
+
push(@err_namelist, '呼び出しエラーです。管理者にお問い合わせ下さい。');
|
148
|
+
|
149
|
+
print_input_error(@err_namelist);
|
150
|
+
|
151
|
+
exit;
|
152
|
+
|
153
|
+
}
|
154
|
+
|
155
|
+
|
156
|
+
|
157
|
+
#$input_jcode = Jcode::getcode($input_value);
|
158
|
+
|
159
|
+
my $guess = guess_encoding($input_value, qw/euc-jp shiftjis 7bit-jis/);
|
160
|
+
|
161
|
+
my $guess_encode = ($guess->name eq 'euc-jp') ? 'eucJP-ms' : $guess->name;
|
162
|
+
|
163
|
+
|
164
|
+
|
165
|
+
#######################################################################
|
166
|
+
|
167
|
+
# パラメータ読み込み
|
168
|
+
|
169
|
+
#######################################################################
|
170
|
+
|
171
|
+
|
172
|
+
|
75
173
|
my @checkboxes_array;
|
76
174
|
|
77
175
|
|
78
176
|
|
79
177
|
foreach $name ($cgi->param) {
|
80
178
|
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
179
|
+
if ($name =~ /^fm_/) { # フォームパラメータ
|
180
|
+
|
181
|
+
$value = $cgi->param($name);
|
182
|
+
|
183
|
+
if($cgi->param('fm_command') eq 'confsend') { # 確認フォームからのときデコード
|
184
|
+
|
185
|
+
$value = pack_param($value);
|
186
|
+
|
187
|
+
}
|
188
|
+
|
189
|
+
#$value = jcode($value, $input_jcode)->sjis;
|
190
|
+
|
191
|
+
$value = ($guess->name ne 'shiftjis') ? encode('utf8', decode($guess_encode, $value)) : $value;
|
192
|
+
|
193
|
+
$fm_param{$name} = $value;
|
194
|
+
|
195
|
+
if($name =~ /^fm_disp_(\w+)/) { # 項目の日本語表示名
|
196
|
+
|
197
|
+
$item_disp{$1} = $value;
|
198
|
+
|
199
|
+
if(!defined $item_value{$1}) {
|
200
|
+
|
201
|
+
push(@item_names, $1);
|
202
|
+
|
203
|
+
$item_value{$1} = '';
|
204
|
+
|
205
|
+
}
|
206
|
+
|
207
|
+
} elsif($name =~ /^fm_need_(\w+)/) { # 項目の入力必須
|
208
|
+
|
209
|
+
$item_need{$1} = $value;
|
210
|
+
|
211
|
+
}
|
212
|
+
|
213
|
+
} elsif($name !~ /^submit$/i) { # 項目('submit'は除く)
|
214
|
+
|
215
|
+
if(!defined $item_value{$name}) {
|
216
|
+
|
217
|
+
push(@item_names, $name);
|
218
|
+
|
219
|
+
}
|
220
|
+
|
221
|
+
@values = $cgi->param($name);
|
222
|
+
|
223
|
+
|
224
|
+
|
225
|
+
my $len = @values;
|
226
|
+
|
227
|
+
if ($len > 1) {
|
228
|
+
|
229
|
+
logger($name . 'はチェックボックスなのです!で項目数は' . $len . 'なのです!(ただし複数選択可能なselectタグかもしれない・・・けど項目の上限を決めておけばいい($lenが上限以下ならselectでも項目をCSVに出す等))');
|
230
|
+
|
231
|
+
for (my $k=0; $k<$len; $k++) {
|
232
|
+
|
233
|
+
logger(@values[$k]);
|
234
|
+
|
235
|
+
}
|
236
|
+
|
237
|
+
#MEMO:
|
238
|
+
|
239
|
+
#確認画面で項目数がここでわかったので、後ろの画面に$nameは$len項目ですと渡せばcsvでいい感じにできるのです!
|
240
|
+
|
241
|
+
#実際の処理には現状確認画面でスペース?区切りか何かにされてしまっているため、項目数がうまくは取れないと思われる(確認画面のhiddenタグ参照の事)
|
242
|
+
|
243
|
+
my $object = {
|
244
|
+
|
245
|
+
name => $name,
|
246
|
+
|
247
|
+
len => $len,
|
248
|
+
|
249
|
+
#values => @values,
|
250
|
+
|
251
|
+
values => [],
|
252
|
+
|
253
|
+
};
|
254
|
+
|
255
|
+
for (my $k=0; $k<$len; $k++) {
|
256
|
+
|
257
|
+
logger(@values[$k]);
|
258
|
+
|
259
|
+
push(@{$object->{values}}, @values[$k]);
|
260
|
+
|
261
|
+
}
|
262
|
+
|
263
|
+
push(@checkboxes_array, $object);
|
264
|
+
|
265
|
+
}
|
266
|
+
|
267
|
+
|
268
|
+
|
269
|
+
$value = join(',', @values);
|
270
|
+
|
271
|
+
if($cgi->param('fm_command') eq 'confsend') { # 確認フォームからのときデコード
|
272
|
+
|
273
|
+
$value = pack_param($value);
|
274
|
+
|
275
|
+
}
|
276
|
+
|
277
|
+
#$item_value{$name} = jcode($value, $input_jcode)->sjis;
|
278
|
+
|
279
|
+
$item_value{$name} = ($guess->name ne 'shiftjis') ? encode('utf8', decode($guess_encode, $value)) : $value;
|
280
|
+
|
281
|
+
|
282
|
+
|
283
|
+
if($item_disp{$name} eq '') {
|
284
|
+
|
285
|
+
$item_disp{$name} = $name;
|
286
|
+
|
287
|
+
}
|
288
|
+
|
289
|
+
}
|
174
290
|
|
175
291
|
}
|
176
292
|
|
@@ -180,19 +296,173 @@
|
|
180
296
|
|
181
297
|
if ($len > 0) {
|
182
298
|
|
183
|
-
|
299
|
+
logger('新規オブジェクト配列は' . $len);
|
184
|
-
|
300
|
+
|
185
|
-
|
301
|
+
for (my $i=0; $i<$len; $i++) {
|
302
|
+
|
186
|
-
|
303
|
+
logger(@checkboxes_array[$i]->{name});
|
304
|
+
|
187
|
-
|
305
|
+
logger(Dumper @checkboxes_array[$i]);
|
188
|
-
|
306
|
+
|
189
|
-
|
307
|
+
}
|
190
|
-
|
308
|
+
|
191
|
-
}
|
309
|
+
}
|
310
|
+
|
311
|
+
|
312
|
+
|
192
|
-
|
313
|
+
foreach (keys %fm_param) {
|
314
|
+
|
193
|
-
|
315
|
+
print "\$fm_param\{$_\} = $fm_param{$_}<br>\n";
|
316
|
+
|
194
|
-
|
317
|
+
}
|
318
|
+
|
195
|
-
|
319
|
+
print "HTMLにかけるように変更";
|
320
|
+
|
321
|
+
foreach (@item_names) {
|
322
|
+
|
323
|
+
my $name = conv_html($item_disp{$_});
|
324
|
+
|
325
|
+
my $value = conv_html($item_value{$_});
|
326
|
+
|
327
|
+
print "$name:$value ($item_need{$_})<br>\n";
|
328
|
+
|
329
|
+
|
330
|
+
|
331
|
+
}
|
332
|
+
|
333
|
+
exit;
|
334
|
+
|
335
|
+
|
336
|
+
|
337
|
+
### csvに書けるように変換
|
338
|
+
|
339
|
+
sub conv_csv {
|
340
|
+
|
341
|
+
my ($str) = @_;
|
342
|
+
|
343
|
+
# $str =~ s/</</g;
|
344
|
+
|
345
|
+
# $str =~ s/>/>/g;
|
346
|
+
|
347
|
+
$str =~ s/\t//g;
|
348
|
+
|
349
|
+
$str =~ s/\r//g;
|
350
|
+
|
351
|
+
$str =~ s/\n//g;
|
352
|
+
|
353
|
+
$str =~ s/\,/"\,\"/g;
|
354
|
+
|
355
|
+
#$str =~ s/"/""/g;
|
356
|
+
|
357
|
+
return '"' . $str . '"';
|
358
|
+
|
359
|
+
#return '' . $str . '';
|
360
|
+
|
361
|
+
}
|
362
|
+
|
363
|
+
sub conv_tsv {
|
364
|
+
|
365
|
+
my ($str) = @_;
|
366
|
+
|
367
|
+
# $str =~ s/</</g;
|
368
|
+
|
369
|
+
# $str =~ s/>/>/g;
|
370
|
+
|
371
|
+
$str =~ s/\t//g;
|
372
|
+
|
373
|
+
$str =~ s/\r//g;
|
374
|
+
|
375
|
+
$str =~ s/\n//g;
|
376
|
+
|
377
|
+
$str =~ s/\,/"\t\"/g;
|
378
|
+
|
379
|
+
# $str =~ s/"/""/g;
|
380
|
+
|
381
|
+
return '"' . $str . '"';
|
382
|
+
|
383
|
+
#return '' . $str . '';
|
384
|
+
|
385
|
+
}
|
386
|
+
|
387
|
+
|
388
|
+
|
389
|
+
### htmlで表示できるように変換
|
390
|
+
|
391
|
+
sub conv_html {
|
392
|
+
|
393
|
+
my ($str) = @_;
|
394
|
+
|
395
|
+
|
396
|
+
|
397
|
+
$str =~ s/</</g;
|
398
|
+
|
399
|
+
$str =~ s/>/>/g;
|
400
|
+
|
401
|
+
$str =~ s/\t//g;
|
402
|
+
|
403
|
+
$str =~ s/\r//g;
|
404
|
+
|
405
|
+
$str =~ s/\,/ /g;
|
406
|
+
|
407
|
+
$str =~ s/\n/<br>\n/g;
|
408
|
+
|
409
|
+
|
410
|
+
|
411
|
+
return $str;
|
412
|
+
|
413
|
+
}
|
414
|
+
|
415
|
+
|
416
|
+
|
417
|
+
### htmlで表示できるように変換
|
418
|
+
|
419
|
+
sub conv_html2 {
|
420
|
+
|
421
|
+
my ($str) = @_;
|
422
|
+
|
423
|
+
|
424
|
+
|
425
|
+
$str =~ s/</</g;
|
426
|
+
|
427
|
+
$str =~ s/>/>/g;
|
428
|
+
|
429
|
+
$str =~ s/\t//g;
|
430
|
+
|
431
|
+
$str =~ s/\r//g;
|
432
|
+
|
433
|
+
#$str =~ s/\,/ /g;
|
434
|
+
|
435
|
+
$str =~ s/\n/<br>\n/g;
|
436
|
+
|
437
|
+
|
438
|
+
|
439
|
+
return $str;
|
440
|
+
|
441
|
+
}
|
442
|
+
|
443
|
+
sub conv_mail {
|
444
|
+
|
445
|
+
my ($str) = @_;
|
446
|
+
|
447
|
+
# $str =~ s/</</g;
|
448
|
+
|
449
|
+
# $str =~ s/>/>/g;
|
450
|
+
|
451
|
+
$str =~ s/\t//g;
|
452
|
+
|
453
|
+
$str =~ s/\r//g;
|
454
|
+
|
455
|
+
$str =~ s/\n//g;
|
456
|
+
|
457
|
+
$str =~ s/\,/"\t\"/g;
|
458
|
+
|
459
|
+
# $str =~ s/"/""/g;
|
460
|
+
|
461
|
+
return '"' . $str . '"';
|
462
|
+
|
463
|
+
#return '' . $str . '';
|
464
|
+
|
465
|
+
}
|
196
466
|
|
197
467
|
|
198
468
|
|
@@ -200,15 +470,15 @@
|
|
200
470
|
|
201
471
|
sub unpack_param {
|
202
472
|
|
203
|
-
|
473
|
+
my ($str) = @_;
|
204
|
-
|
205
|
-
|
206
|
-
|
474
|
+
|
475
|
+
|
476
|
+
|
207
|
-
|
477
|
+
$str =~ s/([^\w.\/\-@ ])/'%'.unpack('H2',$1)/eg;
|
208
|
-
|
209
|
-
|
210
|
-
|
478
|
+
|
479
|
+
|
480
|
+
|
211
|
-
|
481
|
+
return $str;
|
212
482
|
|
213
483
|
}
|
214
484
|
|
@@ -218,17 +488,41 @@
|
|
218
488
|
|
219
489
|
sub pack_param {
|
220
490
|
|
221
|
-
|
491
|
+
my ($str) = @_;
|
222
|
-
|
223
|
-
|
224
|
-
|
492
|
+
|
493
|
+
|
494
|
+
|
225
|
-
|
495
|
+
$str =~ s/%([A-Fa-f0-9]{2})/pack('H2', $1)/eg;
|
226
|
-
|
227
|
-
|
228
|
-
|
496
|
+
|
497
|
+
|
498
|
+
|
229
|
-
|
499
|
+
return $str;
|
230
|
-
|
500
|
+
|
231
|
-
}
|
501
|
+
}
|
502
|
+
|
503
|
+
|
504
|
+
|
505
|
+
sub conv_ahtml {
|
506
|
+
|
507
|
+
my ($str) = @_;
|
508
|
+
|
509
|
+
# $str =~ s/</</g;
|
510
|
+
|
511
|
+
# $str =~ s/>/>/g;
|
512
|
+
|
513
|
+
$str =~ s/\t//g;
|
514
|
+
|
515
|
+
$str =~ s/\r//g;
|
516
|
+
|
517
|
+
$str =~ s/\n/<br>\n/g;
|
518
|
+
|
519
|
+
|
520
|
+
|
521
|
+
return $str;
|
522
|
+
|
523
|
+
}
|
524
|
+
|
525
|
+
|
232
526
|
|
233
527
|
|
234
528
|
|
2
入力に至るまでの概要を記載しました
test
CHANGED
File without changes
|
test
CHANGED
@@ -12,7 +12,9 @@
|
|
12
12
|
|
13
13
|
ソースコードは抜粋ですが、
|
14
14
|
|
15
|
-
|
15
|
+
```HTML
|
16
|
+
|
17
|
+
|
16
18
|
|
17
19
|
<input type="text" name="name" id="name" value="名前" size="30">
|
18
20
|
|
@@ -22,6 +24,8 @@
|
|
22
24
|
|
23
25
|
<input type="hidden" name="fm_need_name" id="fm_need_name" value="1">
|
24
26
|
|
27
|
+
```
|
28
|
+
|
25
29
|
fm_disp_項目名 があるものには、項目名を
|
26
30
|
|
27
31
|
fm_need_項目名
|
1
発生がおきるまでのフローを記載しました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -8,6 +8,36 @@
|
|
8
8
|
|
9
9
|
以下のようにパラメーターを取得しています。
|
10
10
|
|
11
|
+
|
12
|
+
|
13
|
+
ソースコードは抜粋ですが、
|
14
|
+
|
15
|
+
入力フォームには
|
16
|
+
|
17
|
+
<input type="text" name="name" id="name" value="名前" size="30">
|
18
|
+
|
19
|
+
に対応するパラメーター
|
20
|
+
|
21
|
+
<input type="hidden" name="fm_disp_name" id="fm_disp_name" value="お名前">
|
22
|
+
|
23
|
+
<input type="hidden" name="fm_need_name" id="fm_need_name" value="1">
|
24
|
+
|
25
|
+
fm_disp_項目名 があるものには、項目名を
|
26
|
+
|
27
|
+
fm_need_項目名
|
28
|
+
|
29
|
+
を受け取る仕組みです。
|
30
|
+
|
31
|
+
|
32
|
+
|
33
|
+
フォームから入力した全角文字が文字化けしてしまいます。
|
34
|
+
|
35
|
+
結果表示すると
|
36
|
+
|
37
|
+
ãåå??????:Valueãåå値
|
38
|
+
|
39
|
+
のようになってしまいます。
|
40
|
+
|
11
41
|
```perl
|
12
42
|
|
13
43
|
コード
|