php4 チェックボックス ラジオボタンの値の取得
sample4.html
<!DOCTYPE HTML> <html lang="ja"> <head> <meta charset="UTF-8"> <title>php フォームに入力した内容を取得する!</title> </head> <body> <form action="sample4.php" method="post"> <dl> <dt>性別:</dt> <dd> <input id="gender_male" type="radio" name="gender" value="男性"> <label for="gender_male">男性</label> <input id="gender_female" type="radio" name="gender" value="女性"> <label for="gender_female">女性</label> </dd> </dl> <input type="submit" value="送信する"> </form> </body> </html>
sample4.php
<!DOCTYPE HTML> <html lang="ja"> <head> <meta charset="UTF-8"> <title>php フォームに入力した内容を取得する!</title> </head> <body> <?php echo('性別:' .htmlspecialchars($_POST['gender'],ENT_QUOTES)); ?> </body> </html>
ラジオボタンにも「htmlspecialchars」が必要!
安全性を高めるため。。。