複数選択可能なチェックボックスの値を取得する


《HTML》

<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<title>複数選択可能なチェックボックスの値を取得する</title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<div id="wrap">
<div id="head">
<h1>複数選択可能なチェックボックスの値を取得する</h1>
</div>
<div id="content">
<form action="sample12.php" method="get">
<dl>
<dt>ご予約希望日(複数選択可):</dt>
<dd>
<ul>
<li><input id="reserve_1" type="checkbox" name="reserve[]" value="1/1"><label for="reserve_1">1月 1日</label></li>
<li><input id="reserve_2" type="checkbox" name="reserve[]" value="1/2"><label for="reserve_2">1月 2日</label></li>
<li><input id="reserve_3" type="checkbox" name="reserve[]" value="1/3"><label for="reserve_3">1月 3日</label></li>
</ul>
</dd>
</dl>
<input type="submit" value="送信する">
</form>
</div>
</div>
</body>
</html>


PHP

<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<title>複数選択可能なチェックボックスの値を取得する</title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<div id="wrap">
<div id="head">
<h1>複数選択可能なチェックボックスの値を取得する</h1>
</div>

<div id="content">
<p style="margin-top: 200px">
ご予約日:<br>
<?php
foreach($_REQUEST['reserve'] as $reserve) {
	print(htmlspecialchars($reserve, ENT_QUOTES));
}
?>
</p>
</div>
</div>
</body>
</html>