回答編集履歴
1
追記
test
CHANGED
@@ -113,3 +113,217 @@
|
|
113
113
|
```
|
114
114
|
|
115
115
|
最初に指摘した部分が`if (isset($_POST ["register"])) {}`の外にあるため、エラーがあっても表示できません。
|
116
|
+
|
117
|
+
|
118
|
+
|
119
|
+
---
|
120
|
+
|
121
|
+
追記
|
122
|
+
|
123
|
+
他の方が指摘されていたように、エラーメッセージの表示場所に問題があるので、その点も踏まえて次のようにするとどうでしょうか。
|
124
|
+
|
125
|
+
```PHP
|
126
|
+
|
127
|
+
<?
|
128
|
+
|
129
|
+
//送信ボタンが押されたら//
|
130
|
+
|
131
|
+
$error_message = array (); //<--ここ$error_messageを定義
|
132
|
+
|
133
|
+
if (isset($_POST ["register"])) {
|
134
|
+
|
135
|
+
//エラーメッセージを格納する配列を作成
|
136
|
+
|
137
|
+
if ($_POST ["onamae"]!=="") {
|
138
|
+
|
139
|
+
//データがセットされていたら各変数にPOSTのデータを格納
|
140
|
+
|
141
|
+
$onamae = htmlspecialchars($_POST["onamae"],ENT_QUOTES);
|
142
|
+
|
143
|
+
//各データがなかったらエラーメッセージを配列に格納
|
144
|
+
|
145
|
+
}else{
|
146
|
+
|
147
|
+
$error_message[] = "お名前を入力して下さい。<br>";
|
148
|
+
|
149
|
+
}
|
150
|
+
|
151
|
+
|
152
|
+
|
153
|
+
if ($_POST["mailadress"]!=="") {
|
154
|
+
|
155
|
+
$mailadress = htmlspecialchars($_POST["mailadress"],ENT_QUOTES);
|
156
|
+
|
157
|
+
}else{
|
158
|
+
|
159
|
+
$error_message[] = "メールアドレスを入力してください。<br>";
|
160
|
+
|
161
|
+
}
|
162
|
+
|
163
|
+
|
164
|
+
|
165
|
+
if ($_POST["category"]!=="") {
|
166
|
+
|
167
|
+
$mailadress = htmlspecialchars($_POST["category"],ENT_QUOTES);
|
168
|
+
|
169
|
+
}else{
|
170
|
+
|
171
|
+
$error_message[] = "お問い合わせの種類を選択してください。<br>";
|
172
|
+
|
173
|
+
}
|
174
|
+
|
175
|
+
|
176
|
+
|
177
|
+
if ($_POST["interest[]"]!=="") {
|
178
|
+
|
179
|
+
$mailadress = htmlspecialchars($_POST["interest"],ENT_QUOTES);
|
180
|
+
|
181
|
+
}else{
|
182
|
+
|
183
|
+
$error_message[] = "興味のある分野を1つ以上選択してください。<br>";
|
184
|
+
|
185
|
+
}
|
186
|
+
|
187
|
+
if ($_POST["body"]!=="") {
|
188
|
+
|
189
|
+
$mailadress = htmlspecialchars($_POST["body"],ENT_QUOTES);
|
190
|
+
|
191
|
+
}else{
|
192
|
+
|
193
|
+
$error_message[] = "メッセージを入力してください。<br>";
|
194
|
+
|
195
|
+
}
|
196
|
+
|
197
|
+
//エラーが無い時
|
198
|
+
|
199
|
+
if (!count($error_message)){
|
200
|
+
|
201
|
+
//確認ページヘ
|
202
|
+
|
203
|
+
header("Location:confirm.php");
|
204
|
+
|
205
|
+
exit;
|
206
|
+
|
207
|
+
}
|
208
|
+
|
209
|
+
}
|
210
|
+
|
211
|
+
?>
|
212
|
+
|
213
|
+
<!DOCTYPE HTML>
|
214
|
+
|
215
|
+
<html>
|
216
|
+
|
217
|
+
<head>
|
218
|
+
|
219
|
+
<title>お問い合わせフォーム</title>
|
220
|
+
|
221
|
+
<meta charset="utf-8">
|
222
|
+
|
223
|
+
</head>
|
224
|
+
|
225
|
+
<body>
|
226
|
+
|
227
|
+
<?php
|
228
|
+
|
229
|
+
//ここに記述することでhtml内で表示させる
|
230
|
+
|
231
|
+
if (count($error_message)) {
|
232
|
+
|
233
|
+
foreach ($error_message as $message){
|
234
|
+
|
235
|
+
print ($message);
|
236
|
+
|
237
|
+
}
|
238
|
+
|
239
|
+
}
|
240
|
+
|
241
|
+
?>
|
242
|
+
|
243
|
+
<form name="form1" method="post"action="confirm.php" >
|
244
|
+
|
245
|
+
|
246
|
+
|
247
|
+
<H1>お問い合わせフォーム</H1>
|
248
|
+
|
249
|
+
・お名前<br>
|
250
|
+
|
251
|
+
<input type="text" name="onamae" >
|
252
|
+
|
253
|
+
<br>
|
254
|
+
|
255
|
+
|
256
|
+
|
257
|
+
・メールアドレス<br>
|
258
|
+
|
259
|
+
<input type="text" name="mailadress">
|
260
|
+
|
261
|
+
<br>
|
262
|
+
|
263
|
+
|
264
|
+
|
265
|
+
・お問い合わせの種類<br>
|
266
|
+
|
267
|
+
<select name="category" >
|
268
|
+
|
269
|
+
<option value=""selected>選んで下さい</option>
|
270
|
+
|
271
|
+
<option value="質問">質問</option>
|
272
|
+
|
273
|
+
<option value="要望">要望</option>
|
274
|
+
|
275
|
+
<option value="その他お問い合わせ">その他お問い合わせ</option>
|
276
|
+
|
277
|
+
</select>
|
278
|
+
|
279
|
+
<br>
|
280
|
+
|
281
|
+
|
282
|
+
|
283
|
+
・興味のある分野<br>
|
284
|
+
|
285
|
+
<input type="checkbox" name="interest[]" value="HTML">
|
286
|
+
|
287
|
+
HTML<br>
|
288
|
+
|
289
|
+
<input type="checkbox" name="interest[]" value="PHP">
|
290
|
+
|
291
|
+
PHP<br>
|
292
|
+
|
293
|
+
<input type="checkbox" name="interest[]" value="MySQL">
|
294
|
+
|
295
|
+
MySQL<br>
|
296
|
+
|
297
|
+
<input type="checkbox" name="interest[]" value="Linux">
|
298
|
+
|
299
|
+
Linux<br>
|
300
|
+
|
301
|
+
<input type="checkbox" name="interest[]" value="マネジメント">
|
302
|
+
|
303
|
+
マネジメント<br>
|
304
|
+
|
305
|
+
<input type="checkbox" name="interest[]" value="その他">
|
306
|
+
|
307
|
+
その他<br>
|
308
|
+
|
309
|
+
|
310
|
+
|
311
|
+
・メッセージ<br>
|
312
|
+
|
313
|
+
<textarea name="body" cols="30" rows="5"></textarea>
|
314
|
+
|
315
|
+
<br>
|
316
|
+
|
317
|
+
|
318
|
+
|
319
|
+
<input type="submit" name="register value="送信">
|
320
|
+
|
321
|
+
|
322
|
+
|
323
|
+
</form>
|
324
|
+
|
325
|
+
</body>
|
326
|
+
|
327
|
+
</html>
|
328
|
+
|
329
|
+
```
|