回答編集履歴
5
調整
test
CHANGED
@@ -326,12 +326,24 @@
|
|
326
326
|
|
327
327
|
<?php
|
328
328
|
|
329
|
-
foreach($e
|
329
|
+
foreach($checked as $key=>$val){
|
330
|
+
|
330
|
-
|
331
|
+
print $key.")".$val.":";
|
332
|
+
|
333
|
+
if(isset($error[$key])){
|
334
|
+
|
331
|
-
print $key."
|
335
|
+
print $error[$key]."[".htmlspecialchars(@$number[$key])."]<br>";
|
336
|
+
|
337
|
+
}else{
|
338
|
+
|
339
|
+
print "[".htmlspecialchars(@$number[$key])."]<br>";
|
340
|
+
|
341
|
+
}
|
332
342
|
|
333
343
|
}
|
334
344
|
|
335
345
|
?>
|
336
346
|
|
347
|
+
|
348
|
+
|
337
349
|
```
|
4
調整
test
CHANGED
@@ -170,10 +170,168 @@
|
|
170
170
|
|
171
171
|
```PHP
|
172
172
|
|
173
|
+
<?PHP
|
174
|
+
|
175
|
+
$checked=filter_input(INPUT_POST,"checked",FILTER_DEFAULT,["options"=>["default"=>[]],"flags"=>FILTER_REQUIRE_ARRAY]);
|
176
|
+
|
177
|
+
$number=filter_input(INPUT_POST,"number",FILTER_DEFAULT,FILTER_REQUIRE_ARRAY);
|
178
|
+
|
179
|
+
$error=[];
|
180
|
+
|
181
|
+
foreach(array_keys($checked) as $key){
|
182
|
+
|
183
|
+
if(!isset($number[$key]) or (int)$number[$key]===0){
|
184
|
+
|
185
|
+
$error[$key]="<span style='color:red'>数書け!!</span>";
|
186
|
+
|
187
|
+
}
|
188
|
+
|
189
|
+
};
|
190
|
+
|
191
|
+
?>
|
192
|
+
|
193
|
+
<script>
|
194
|
+
|
195
|
+
HTMLElement.prototype.trigger=function(eventStr){
|
196
|
+
|
197
|
+
if (document.createEvent) {
|
198
|
+
|
199
|
+
var e = document.createEvent("HTMLEvents");
|
200
|
+
|
201
|
+
e.initEvent(eventStr, true, true );
|
202
|
+
|
203
|
+
return this.dispatchEvent(e);
|
204
|
+
|
205
|
+
} else {
|
206
|
+
|
207
|
+
var e = document.createEventObject();
|
208
|
+
|
209
|
+
return this.fireEvent("on"+eventStr, e);
|
210
|
+
|
211
|
+
}
|
212
|
+
|
213
|
+
};
|
214
|
+
|
215
|
+
window.addEventListener('DOMContentLoaded', function(e){
|
216
|
+
|
217
|
+
[].forEach.call(document.querySelectorAll('.checkbox_input_1'),function(x){
|
218
|
+
|
219
|
+
x.addEventListener('change',function(e){
|
220
|
+
|
221
|
+
document.querySelector('[name="'+x.dataset["target"]+'"]').disabled=!e.target.checked;
|
222
|
+
|
223
|
+
});
|
224
|
+
|
225
|
+
x.trigger('change');
|
226
|
+
|
227
|
+
});
|
228
|
+
|
229
|
+
});
|
230
|
+
|
231
|
+
</script>
|
232
|
+
|
233
|
+
<form method="post">
|
234
|
+
|
235
|
+
<p class="part_1">
|
236
|
+
|
237
|
+
<label class="checkbox_text">
|
238
|
+
|
239
|
+
<input class="checkbox_input_1" type="checkbox" name="checked[0]" data-target="number[0]" value="カタログ一式(総合カタログ+製品カタログ全種)">
|
240
|
+
|
241
|
+
<span class="checkbox_parts_1">カタログ一式(総合カタログ+製品カタログ全種)</span>
|
242
|
+
|
243
|
+
</label>
|
244
|
+
|
245
|
+
</p>
|
246
|
+
|
247
|
+
<div class="cArea_2">
|
248
|
+
|
249
|
+
<p class="part_2">
|
250
|
+
|
251
|
+
<input name="number[0]" value="" maxlength="3" type="text" disabled required> 部
|
252
|
+
|
253
|
+
</p>
|
254
|
+
|
255
|
+
</div>
|
256
|
+
|
257
|
+
<p class="part_1">
|
258
|
+
|
259
|
+
<label class="checkbox_text">
|
260
|
+
|
261
|
+
<input class="checkbox_input_1" type="checkbox" name="checked[1]" data-target="number[1]" value="総合カタログ">
|
262
|
+
|
263
|
+
<span class="checkbox_parts_1">総合カタログ</span>
|
264
|
+
|
265
|
+
</label>
|
266
|
+
|
267
|
+
</p>
|
268
|
+
|
269
|
+
<div class="cArea_2">
|
270
|
+
|
271
|
+
<p class="part_2">
|
272
|
+
|
273
|
+
<input name="number[1]" value="" maxlength="3" type="text" disabled required> 部
|
274
|
+
|
275
|
+
</p>
|
276
|
+
|
277
|
+
</div>
|
278
|
+
|
279
|
+
<p class="part_1">
|
280
|
+
|
281
|
+
<label class="checkbox_text">
|
282
|
+
|
283
|
+
<input class="checkbox_input_1" type="checkbox" name="checked[2]" data-target="number[2]" value="製品1">
|
284
|
+
|
285
|
+
<span class="checkbox_parts_1">製品1</span>
|
286
|
+
|
287
|
+
</label>
|
288
|
+
|
289
|
+
</p>
|
290
|
+
|
291
|
+
<div class="cArea_2">
|
292
|
+
|
293
|
+
<p class="part_2">
|
294
|
+
|
295
|
+
<input name="number[2]" value="" maxlength="3" type="text" disabled required> 部
|
296
|
+
|
297
|
+
</p>
|
298
|
+
|
299
|
+
</div>
|
300
|
+
|
301
|
+
<p class="part_1">
|
302
|
+
|
303
|
+
<label class="checkbox_text">
|
304
|
+
|
305
|
+
<input class="checkbox_input_1" type="checkbox" name="checked[3]" data-target="number[3]" value="製品2">
|
306
|
+
|
307
|
+
<span class="checkbox_parts_1">製品2</span>
|
308
|
+
|
309
|
+
</label>
|
310
|
+
|
311
|
+
</p>
|
312
|
+
|
313
|
+
<div class="cArea_2">
|
314
|
+
|
315
|
+
<p class="part_2">
|
316
|
+
|
317
|
+
<input name="number[3]" value="" maxlength="3" type="text" disabled required> 部
|
318
|
+
|
319
|
+
</p>
|
320
|
+
|
321
|
+
</div>
|
322
|
+
|
323
|
+
<input type="submit" value="go">
|
324
|
+
|
325
|
+
</form>
|
326
|
+
|
327
|
+
<?php
|
328
|
+
|
173
329
|
foreach($error as $key=>$val){
|
174
330
|
|
175
|
-
print $key.":".$val."<br>";
|
331
|
+
print $key.":".$val."[".htmlspecialchars($number[$key])."]<br>";
|
176
332
|
|
177
333
|
}
|
178
334
|
|
335
|
+
?>
|
336
|
+
|
179
337
|
```
|
3
調整
test
CHANGED
@@ -68,8 +68,6 @@
|
|
68
68
|
|
69
69
|
<form method="post">
|
70
70
|
|
71
|
-
<label>
|
72
|
-
|
73
71
|
<p class="part_1">
|
74
72
|
|
75
73
|
<label class="checkbox_text">
|
@@ -90,11 +88,7 @@
|
|
90
88
|
|
91
89
|
</p>
|
92
90
|
|
93
|
-
<
|
91
|
+
</div>
|
94
|
-
|
95
|
-
print isset($error[0])?$error[0]:"";
|
96
|
-
|
97
|
-
?>
|
98
92
|
|
99
93
|
<p class="part_1">
|
100
94
|
|
@@ -116,11 +110,7 @@
|
|
116
110
|
|
117
111
|
</p>
|
118
112
|
|
119
|
-
<
|
113
|
+
</div>
|
120
|
-
|
121
|
-
print isset($error[1])?$error[1]:"";
|
122
|
-
|
123
|
-
?>
|
124
114
|
|
125
115
|
<p class="part_1">
|
126
116
|
|
@@ -142,11 +132,7 @@
|
|
142
132
|
|
143
133
|
</p>
|
144
134
|
|
145
|
-
<
|
135
|
+
</div>
|
146
|
-
|
147
|
-
print isset($error[2])?$error[2]:"";
|
148
|
-
|
149
|
-
?>
|
150
136
|
|
151
137
|
<p class="part_1">
|
152
138
|
|
@@ -168,14 +154,26 @@
|
|
168
154
|
|
169
155
|
</p>
|
170
156
|
|
171
|
-
<
|
157
|
+
</div>
|
172
|
-
|
173
|
-
print isset($error[3])?$error[3]:"";
|
174
|
-
|
175
|
-
?>
|
176
158
|
|
177
159
|
<input type="submit" value="go">
|
178
160
|
|
179
161
|
</form>
|
180
162
|
|
163
|
+
|
164
|
+
|
181
165
|
```
|
166
|
+
|
167
|
+
|
168
|
+
|
169
|
+
# errorをまとめて表記
|
170
|
+
|
171
|
+
```PHP
|
172
|
+
|
173
|
+
foreach($error as $key=>$val){
|
174
|
+
|
175
|
+
print $key.":".$val."<br>";
|
176
|
+
|
177
|
+
}
|
178
|
+
|
179
|
+
```
|
2
調整
test
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
こんな感じで
|
2
2
|
|
3
|
-
|
3
|
+
JSの初期処理を追加
|
4
4
|
|
5
5
|
```PHP
|
6
6
|
|
@@ -28,6 +28,26 @@
|
|
28
28
|
|
29
29
|
<script>
|
30
30
|
|
31
|
+
HTMLElement.prototype.trigger=function(eventStr){
|
32
|
+
|
33
|
+
if (document.createEvent) {
|
34
|
+
|
35
|
+
var e = document.createEvent("HTMLEvents");
|
36
|
+
|
37
|
+
e.initEvent(eventStr, true, true );
|
38
|
+
|
39
|
+
return this.dispatchEvent(e);
|
40
|
+
|
41
|
+
} else {
|
42
|
+
|
43
|
+
var e = document.createEventObject();
|
44
|
+
|
45
|
+
return this.fireEvent("on"+eventStr, e);
|
46
|
+
|
47
|
+
}
|
48
|
+
|
49
|
+
};
|
50
|
+
|
31
51
|
window.addEventListener('DOMContentLoaded', function(e){
|
32
52
|
|
33
53
|
[].forEach.call(document.querySelectorAll('.checkbox_input_1'),function(x){
|
@@ -37,6 +57,8 @@
|
|
37
57
|
document.querySelector('[name="'+x.dataset["target"]+'"]').disabled=!e.target.checked;
|
38
58
|
|
39
59
|
});
|
60
|
+
|
61
|
+
x.trigger('change');
|
40
62
|
|
41
63
|
});
|
42
64
|
|
1
調整
test
CHANGED
@@ -6,7 +6,9 @@
|
|
6
6
|
|
7
7
|
<?PHP
|
8
8
|
|
9
|
-
$checked=filter_input(INPUT_POST,"checked",FILTER_DEFAULT,FILTER_REQUIRE_ARRAY);
|
9
|
+
//修正:$checked=filter_input(INPUT_POST,"checked",FILTER_DEFAULT,FILTER_REQUIRE_ARRAY);
|
10
|
+
|
11
|
+
$checked=filter_input(INPUT_POST,"checked",FILTER_DEFAULT,["options"=>["default"=>[]],"flags"=>FILTER_REQUIRE_ARRAY]);
|
10
12
|
|
11
13
|
$number=filter_input(INPUT_POST,"number",FILTER_VALIDATE_INT,FILTER_REQUIRE_ARRAY);
|
12
14
|
|