回答編集履歴
2
sample
test
CHANGED
@@ -26,7 +26,7 @@
|
|
26
26
|
|
27
27
|
ちょっとざつですがsample
|
28
28
|
|
29
|
-
(い
|
29
|
+
(バリデートもサニタイズもしていないので流れだけみて、そのままは流用しないで)
|
30
30
|
|
31
31
|
|
32
32
|
|
1
sample
test
CHANGED
@@ -19,3 +19,141 @@
|
|
19
19
|
|
20
20
|
|
21
21
|
dialogなど新し目のタグで処理するとスマートに見えると思います。
|
22
|
+
|
23
|
+
|
24
|
+
|
25
|
+
# sample
|
26
|
+
|
27
|
+
ちょっとざつですがsample
|
28
|
+
|
29
|
+
(いろいろ問題があるので流れだけみて、そのままは流用しないで)
|
30
|
+
|
31
|
+
|
32
|
+
|
33
|
+
```PHP
|
34
|
+
|
35
|
+
<?PHP
|
36
|
+
|
37
|
+
session_start();
|
38
|
+
|
39
|
+
$flg=filter_input(INPUT_POST,"flg");
|
40
|
+
|
41
|
+
$a=filter_input(INPUT_POST,"a");
|
42
|
+
|
43
|
+
$b=filter_input(INPUT_POST,"b");
|
44
|
+
|
45
|
+
if($flg==1){
|
46
|
+
|
47
|
+
$_SESSION["a"]=$a;
|
48
|
+
|
49
|
+
$_SESSION["b"]=$b;
|
50
|
+
|
51
|
+
print json_encode(["a"=>$a,"b"=>$b]);
|
52
|
+
|
53
|
+
exit;
|
54
|
+
|
55
|
+
}elseif($flg==2){
|
56
|
+
|
57
|
+
if(!isset($_SESSION["a"])){
|
58
|
+
|
59
|
+
header('Location:'.$_SERVER["SCRIPT_NAME"]);
|
60
|
+
|
61
|
+
exit;
|
62
|
+
|
63
|
+
}
|
64
|
+
|
65
|
+
print "完了";
|
66
|
+
|
67
|
+
print "a=".htmlspecialchars($_SESSION["a"])."/";
|
68
|
+
|
69
|
+
print "b=".htmlspecialchars($_SESSION["b"])."で登録";
|
70
|
+
|
71
|
+
unset($_SESSION["a"]);
|
72
|
+
|
73
|
+
unset($_SESSION["b"]);
|
74
|
+
|
75
|
+
exit;
|
76
|
+
|
77
|
+
}else{
|
78
|
+
|
79
|
+
print_r($_SESSION);
|
80
|
+
|
81
|
+
unset($_SESSION["a"]);
|
82
|
+
|
83
|
+
unset($_SESSION["b"]);
|
84
|
+
|
85
|
+
}
|
86
|
+
|
87
|
+
?>
|
88
|
+
|
89
|
+
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
|
90
|
+
|
91
|
+
<script>
|
92
|
+
|
93
|
+
$(function(){
|
94
|
+
|
95
|
+
|
96
|
+
|
97
|
+
$(document).on('click','#close',function(e){
|
98
|
+
|
99
|
+
$('#dl').removeAttr('open');
|
100
|
+
|
101
|
+
});
|
102
|
+
|
103
|
+
$('#f1').on('submit',function(e){
|
104
|
+
|
105
|
+
e.preventDefault();
|
106
|
+
|
107
|
+
$.ajax({
|
108
|
+
|
109
|
+
"type":"post",
|
110
|
+
|
111
|
+
"data":new FormData($(this).get(0)),
|
112
|
+
|
113
|
+
"dataType":"json",
|
114
|
+
|
115
|
+
"cache":false,
|
116
|
+
|
117
|
+
"processData": false,
|
118
|
+
|
119
|
+
"contentType": false,
|
120
|
+
|
121
|
+
}).done(function(data){
|
122
|
+
|
123
|
+
$('#dl').remove();
|
124
|
+
|
125
|
+
var form=$('<form method="post">');
|
126
|
+
|
127
|
+
$('<div>').text("a:"+data.a).appendTo(form);
|
128
|
+
|
129
|
+
$('<div>').text("b:"+data.b).appendTo(form);
|
130
|
+
|
131
|
+
$('<input type="hidden" name="flg" value="2">').appendTo(form);
|
132
|
+
|
133
|
+
$('<div>').html($('<input type="submit" value="登録"><input type="button" id="close" value="閉じる">')).appendTo(form);
|
134
|
+
|
135
|
+
$('<dialog id="dl" open>').html(form).appendTo('body');
|
136
|
+
|
137
|
+
console.log(data);
|
138
|
+
|
139
|
+
});
|
140
|
+
|
141
|
+
});
|
142
|
+
|
143
|
+
});
|
144
|
+
|
145
|
+
</script>
|
146
|
+
|
147
|
+
<form method="post" id="f1">
|
148
|
+
|
149
|
+
a:<input type="text" name="a"><br>
|
150
|
+
|
151
|
+
b:<input type="text" name="b"><br>
|
152
|
+
|
153
|
+
<input type="submit" value="send">
|
154
|
+
|
155
|
+
<input type="hidden" name="flg" value="1">
|
156
|
+
|
157
|
+
</form>
|
158
|
+
|
159
|
+
```
|