PHPでメンバー登録フォームと入力チェック画面を作る(2ページ) | 55日目
入力画面
<!DOCTYPE HTML> <html lang="ja"> <head> <meta charset="utf-8"> <title>メンバー登録フォーム</title> <style> body{ /*text-align:center; */ } table{ text-align:left; /* border-collapse:collapse; */ } </style> </head> <body> <h1>メンバー登録</h1> <hr> <br> <table width="500" border="1"> <tr> <td> <form method="post" action="check.php" name="member_account" > <label for ="mailadd" ><p>メールアドレス</label> <input type="text" name="mailadd" size=70 maxlength=255></p> <p></td> </tr> <tr><td> <input type="checkbox" name="mobile" value="1" >携帯アドレスの場合チェックする</p></td></tr> <tr><td> <p>性別<input type="radio" name="gender" value="male" checked><label for= "gender_male">男性</label> <input id="gender_female" input type="radio" name="gender" value="female"><label for= "gender_female">女性</label></p></td></tr> <tr><td><p>会費負担 <select name="futan"> <option value="100">全額負担</option> <option value="50">半額負担</option> <option value="0">無料</option> </select></td></tr> <tr><td><p>コメント <textarea name="comment" cols="80" rows="5"></textarea> </p></td></tr> <tr><td><input type="submit" value="登録" > <input type="reset" value="クリア"></td></tr> </form> </table ></body> </html>
入力チェック画面
非常に荒削りな表示ですが、しっかり入力した内容を受け取っています
<!DOCTYPE HTML> <html> <head> <meta charset="utf-8"> <title>入力データチェック画面</title> </head> <body> <?php $mailadd = $_POST['mailadd']; $mobile = $_POST['mobile']; $gender = $_POST['gender']; $futan = $_POST['futan']; $comment = $_POST['comment']; $mailadd = htmlspecialchars(($mailadd), ENT_QUOTES); print('メールアドレス' . $mailadd. "<br>\n"); print('携帯アドレス' . $mobile. "<br>\n"); print('性別' . $gender. "<br>\n"); print('会費負担' . $futan. "<br>\n"); $comment = htmlspecialchars(($comment), ENT_QUOTES); $comment = nl2br($comment); print('コメント' .$comment. "<br>\n"); ?> </body> </html>
- nl2brは改行指定の意味です
- 今回は使用していませんが action="xx@xxx.com"(入力形式がメール)の時は enctype="text/plain" を使って文字化けを防ぎます