回答編集履歴
1
sample
test
CHANGED
@@ -7,3 +7,133 @@
|
|
7
7
|
また中身が空文字""のときにNULLと比較してしまうのでまったくだめです
|
8
8
|
|
9
9
|
そもそもNULLを検出する演算子は等号ではなくisです
|
10
|
+
|
11
|
+
|
12
|
+
|
13
|
+
# sample
|
14
|
+
|
15
|
+
ちゃんとやるなら最低限こうしてください
|
16
|
+
|
17
|
+
```PHP
|
18
|
+
|
19
|
+
<?PHP
|
20
|
+
|
21
|
+
$shift_flag=filter_input(INPUT_POST,"shift_flag");
|
22
|
+
|
23
|
+
$is_null=filter_input(INPUT_POST,"is_null",FILTER_DEFAULT,FILTER_REQUIRE_ARRAY)?:[];
|
24
|
+
|
25
|
+
$set="";
|
26
|
+
|
27
|
+
$data=[];
|
28
|
+
|
29
|
+
if(in_array("shift_flag",$is_null)){
|
30
|
+
|
31
|
+
$set.=",shift_flag = null";
|
32
|
+
|
33
|
+
}elseif(!is_null($shift_flag)){
|
34
|
+
|
35
|
+
$set.=",shift_flag = ?";
|
36
|
+
|
37
|
+
$data[]=$shift_flag;
|
38
|
+
|
39
|
+
}
|
40
|
+
|
41
|
+
print $set."<br>";
|
42
|
+
|
43
|
+
print_r($data);
|
44
|
+
|
45
|
+
?>
|
46
|
+
|
47
|
+
<script>
|
48
|
+
|
49
|
+
window.addEventListener('DOMContentLoaded', function(e){
|
50
|
+
|
51
|
+
[].forEach.call(document.querySelectorAll('[name="is_null[]"]'),function(x){
|
52
|
+
|
53
|
+
x.addEventListener('change',function(e){
|
54
|
+
|
55
|
+
document.querySelector('[name="'+e.target.value+'"]').disabled=e.target.checked;
|
56
|
+
|
57
|
+
});
|
58
|
+
|
59
|
+
});
|
60
|
+
|
61
|
+
});
|
62
|
+
|
63
|
+
</script>
|
64
|
+
|
65
|
+
<form method="post">
|
66
|
+
|
67
|
+
シフトフラグ:<input type="text" name="shift_flag" value="0" id="shift_flag">
|
68
|
+
|
69
|
+
<label><input type="checkbox" name="is_null[]" value="shift_flag">null</label><br>
|
70
|
+
|
71
|
+
<input type="submit" value="send"></form>
|
72
|
+
|
73
|
+
```
|
74
|
+
|
75
|
+
さらにバリデートを厳密に適用するならこう
|
76
|
+
|
77
|
+
```PHP
|
78
|
+
|
79
|
+
<?PHP
|
80
|
+
|
81
|
+
$shift_flag=filter_input(INPUT_POST,"shift_flag",FILTER_VALIDATE_INT);
|
82
|
+
|
83
|
+
$is_null=filter_input(INPUT_POST,"is_null",FILTER_DEFAULT,FILTER_REQUIRE_ARRAY)?:[];
|
84
|
+
|
85
|
+
$set="";
|
86
|
+
|
87
|
+
$data=[];
|
88
|
+
|
89
|
+
|
90
|
+
|
91
|
+
if(in_array("shift_flag",$is_null)){
|
92
|
+
|
93
|
+
$set.=",shift_flag = null";
|
94
|
+
|
95
|
+
}elseif($shift_flag===false){
|
96
|
+
|
97
|
+
print "error";
|
98
|
+
|
99
|
+
}elseif(!is_null($shift_flag)){
|
100
|
+
|
101
|
+
$set.=",shift_flag = ?";
|
102
|
+
|
103
|
+
$data[]=$shift_flag;
|
104
|
+
|
105
|
+
}
|
106
|
+
|
107
|
+
print $set."<br>";
|
108
|
+
|
109
|
+
print_r($data);
|
110
|
+
|
111
|
+
?>
|
112
|
+
|
113
|
+
<script>
|
114
|
+
|
115
|
+
window.addEventListener('DOMContentLoaded', function(e){
|
116
|
+
|
117
|
+
[].forEach.call(document.querySelectorAll('[name="is_null[]"]'),function(x){
|
118
|
+
|
119
|
+
x.addEventListener('change',function(e){
|
120
|
+
|
121
|
+
document.querySelector('[name="'+e.target.value+'"]').disabled=e.target.checked;
|
122
|
+
|
123
|
+
});
|
124
|
+
|
125
|
+
});
|
126
|
+
|
127
|
+
});
|
128
|
+
|
129
|
+
</script>
|
130
|
+
|
131
|
+
<form method="post">
|
132
|
+
|
133
|
+
シフトフラグ:<input type="text" name="shift_flag" value="0" id="shift_flag" pattern="\d+" required>
|
134
|
+
|
135
|
+
<label><input type="checkbox" name="is_null[]" value="shift_flag">null</label><br>
|
136
|
+
|
137
|
+
<input type="submit" value="send"></form>
|
138
|
+
|
139
|
+
```
|