お問い合わせフォーム確認テスト1

お問い合わせフォーム確認テスト

index.php

<!DOCTYPE HTML>
<html lang="ja">
<head>
<meta charset="utf-8">
<title>メッセージ入力画面</title>
<!--[if lt IE 9]>
<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<!--[if lt IE 9]>
<script src="http://cdnjs.cloudflare.com/ajax/libs/modernizr/2.5.3/modernizr.min.js"></script>
<![endif]-->
<style>
article,aside,dialog,figure,footer,header,hgroup,menu,nav,section{display:block}
</style>
<link rel="stylesheet" href="style.css">
</head>

<body>
<h1>メッセージ入力画面</h1>
<p>必要事項を入力して「確認する」ボタンを押してください</p>
<form action="check.php" method="post">
<table>
<tr>
<th>お名前<span class="red">※</span></th>
<td><input type="text" name="name" id="name" size="30" placeholder="例:山田" autofocus required></td>
</tr>
<tr>
<th>メールアドレス<span class="red">※</span></th>
<td><input type="text" name="email" id="email" size="30" placeholder="例:aaa@example.com" required></td>
</tr>
<tr>
<th>メッセージ<span class="red">※</span></th>
<td><textarea name="message" id="message" rows="5" cols="40" placeholder="例:はじめまして" required></textarea></td>
</tr>
<tr>
<td colspan="2" class="button">
<input type="submit" name="sub1" value="確認する">
</td>
</tr>
</table>
</form>
</body>
</html>

check.php

<?php
if(empty($_POST)){
echo'処理終了';
exit;
}

//セッション開始
session_start();

 $name = htmlspecialchars($_POST['name'],ENT_QUOTES);
 $email = htmlspecialchars($_POST['email'],ENT_QUOTES);
 $message = htmlspecialchars($_POST['message'],ENT_QUOTES);
 
 $_SESSION['name'] = $name;
 $_SESSION['email'] = $email;
 $_SESSION['message'] = $message;

?>
<!DOCTYPE HTML>
<html lang="ja">
<head>
<meta charset="utf-8">
<title>メッセージ入力画面</title>
<!--[if lt IE 9]>
<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<!--[if lt IE 9]>
<script src="http://cdnjs.cloudflare.com/ajax/libs/modernizr/2.5.3/modernizr.min.js"></script>
<![endif]-->
<style>
article,aside,dialog,figure,footer,header,hgroup,menu,nav,section{display:block}
</style>
<link rel="stylesheet" href="style.css">
</head>

<body>
<?php
if(empty($_POST['name'])){
  echo'お名前を入力してください';
  exit;
}
if(empty($_POST['email'])){
  echo'メールアドレスを入力してください';
  exit;
}
if(empty($_POST['message'])){
  echo'メッセージを入力してください';
  exit;
}
?>
<h1>確認画面</h1>
<p>内容を確認してください。よろしければ送信ボタンを押してください</p>
<form action="thanks.php" method="post">
<table>
<tr>
<th>お名前</th>
<td><?php echo $name; ?></td>
</tr>
<tr>
<th>メールアドレス</th>
<td><?php echo $email; ?></td>
</tr>
<tr>
<th>メッセージ</th>
<td><?php echo nl2br($message); ?></td>
</tr>
<tr>
<td colspan="2" class="button">
<input type="submit" name="sub1" value="確認する">
</td>
</tr>
</table>
</form>
</body>
</html>