前提・実現したいこと
フォームからradiobuttonの値をPOSTして受け取った先で「このフォームの値で登録しますか?」の確認画面を出すのですが
そのまま登録する分には問題ないのですが、編集と押したら入力していたフォームに値をPOSTでいれなおして編集をかける方法を考えています。
発生している問題・エラーメッセージ
値はしっかり受け取れているのですが、ボタンをcheckedにするにはif文などで1ならcheckedにするみたいなことをたくさん書けばいいのでしょうか?
もとスマートなやり方があれば教えてほしいです。
該当のソースコード
health_use_register.php メインのフォームです
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>保健室利用メモフォーム</title> </head> <body> <h3>保健室利用メモ</h3> <form action="health_use_register_check.php" method="post"> <?php $dsn = 'mysql:dbname=CareSupport;host=localhost;charset=utf8mb4'; $user = 'root'; $password = 'rootg10'; $date = filter_input(INPUT_POST,'date'); $student_num = filter_input(INPUT_POST,'student_num'); $student_name = filter_input(INPUT_POST,'student_name'); $student_teacher = filter_input(INPUT_POST,'student_teacher'); $symptom = filter_input(INPUT_POST,'symptom'); $symptom_time = filter_input(INPUT_POST,'symptom_time'); $symptom_cause = filter_input(INPUT_POST,'symptom_cause'); $taiou = filter_input(INPUT_POST,'taiou'); $symptom_fix = filter_input(INPUT_POST,'symptom_fix'); $memo = filter_input(INPUT_POST,'memo'); $symptom_type = filter_input(INPUT_POST,'symptom_type'); $entry_time = filter_input(INPUT_POST,'entry_time'); $exit_time = filter_input(INPUT_POST,'exit_time'); $staff = filter_input(INPUT_POST,'staff'); ?> <table> <tr> <th>日付:</th> <td><input type="date" id="today" name="date" value="<?php echo $date; ?>"></td> </tr> <tr> <th>入室時間:</th> <td><input type="time" id="time" name="entry_time"></td> </tr> <tr> <th>退出時間:</th> <td><input type="time" id="time" name="exit_time" value="<?php echo $exit_time; ?>"></td> </tr> <tr> <th>学籍番号:</th> <td><input type="text" name="student_num" placeholder="16XX0101" value="<?php echo $student_num; ?>"></td> </tr> <tr> <th>氏名:</th> <td><input type="text" name="student_name" placeholder="電子太郎" value="<?php echo $student_name; ?>"></td> </tr> <tr> <th>性別:</th> <td> <input type="radio" name="gender" value="1">男 <input type="radio" name="gender" value="2">女 </td> </tr> <tr> <th>担任:</th> <td><input type="text" name="student_teacher" value="<?php echo $student_teacher; ?>"></td> </tr> <tr> <th>症状:</th> <td><input type="text" name="symptom" value="<?php echo $symptom; ?>"></td> </tr> <tr> <th>いつから:</th> <td><input type="text" name="symptom_time" value="<?php echo $symptom_time; ?>"></td> </tr> <tr> <th>原因は?:</th> <td><input type="text" name="symptom_cause" value="<?php echo $symptom_cause; ?>"></td> </tr> <tr> <th>対応:</th> <td><input type="text" name="taiou" value="<?php echo $taiou; ?>"></td> </tr> <tr> <th>処置:</th> <td><input type="text" name="symptom_fix" value="<?php echo $symptom_fix ?>"></td> </tr> <tr> <th>症状種別:</th> <td> <input type="radio" name="symptom_type" value="外科">外科 <input type="radio" name="symptom_type" value="内科">内科 <input type="radio" name="symptom_type" value="その他">その他</td> </tr> <tr> <th>メモ:</th> <td><textarea name="memo" value="<?php echo $memo; ?>"></textarea></td> </tr> <tr> <th>対応者:</th> <td><input type="text" name="staff" value="<?php echo $staff; ?>"></td> </tr> </table> <input type="submit" value="確定"> </form> </body> </html>
ここにPOSTして編集ボタンが押されたらメインのフォームに戻してます
health_use_registar_check.php
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>保健室利用メモ確認</title> </head> <body> <?php //session_start(); $date = $_POST['date']; $student_num = $_POST['student_num']; $student_name = $_POST['student_name']; $student_teacher = $_POST['student_teacher']; $symptom = $_POST['symptom']; $symptom_time = $_POST['symptom_time']; $symptom_cause = $_POST['symptom_cause']; $taiou = $_POST['taiou']; $symptom_fix = $_POST['symptom_fix']; $memo = $_POST['memo']; $symptom_type = $_POST['symptom_type']; $entry_time = $_POST['entry_time']; $exit_time = $_POST['exit_time']; $staff = $_POST['staff']; $gender = $_POST['gender']; ?> <table> <tr> <th>日付:</th> <td><?php echo $date; ?></td> </tr> <tr> <th>入室時間:</th> <td><?php echo $entry_time; ?></td> </tr> <tr> <th>退出時間:</th> <td><?php echo $exit_time; ?></td> </tr> <tr> <th>学籍番号:</th> <td><?php echo $student_num; ?></td> </tr> <tr> <th>氏名:</th> <td><?php echo $student_name; ?></td> </tr> <tr> <th>性別:</th> <td><?php echo $gender; ?></td> </tr> <tr> <th>担任:</th> <td><?php echo $student_teacher; ?></td> </tr> <tr> <th>症状:</th> <td><?php echo $symptom; ?></td> </tr> <tr> <th>いつから:</th> <td><?php echo $symptom_time; ?></td> </tr> <tr> <th>原因は?:</th> <td><?php echo $symptom_cause; ?></td> </tr> <tr> <th>対応:</th> <td><?php echo $taiou; ?></td> </tr> <tr> <th>処置:</th> <td><?php echo $symptom_fix; ?></td> </tr> <tr> <th>症状種別:</th> <td><?php echo $symptom_type; ?></td> </tr> <tr> <th>メモ:</th> <td><?php echo $memo; ?></textarea></td> </tr> <tr> <th>対応者:</th> <td><?php echo $staff; ?></td> </tr> </table> <p>こちらの内容で登録しますか?</p> <form action="health_use_register_insert.php" method="post"> <input type="hidden" id="today" name="date" value="<?php echo $date; ?>"> <input type="hidden" id="time" name="entry_time" value="<?php echo $entry_time; ?>"> <input type="hidden" name="exit_time" value="<?php echo $exit_time; ?>"> <input type="hidden" name="student_num" value="<?php echo $student_num; ?>"> <input type="hidden" name="student_name" value="<?php echo $student_name; ?>"> <input type="hidden" name="gender" value="1" value="<?php echo $gender; ?>"> <input type="hidden" name="student_teacher" value="<?php echo $student_teacher; ?>"> <input type="hidden" name="symptom" value="<?php echo $symptom; ?>"> <input type="hidden" name="symptom_time" value="<?php echo $symptom_time; ?>"> <input type="hidden" name="symptom_cause" value="<?php echo $symptom_cause; ?>"> <input type="hidden" name="taiou" value="<?php echo $taiou; ?>"> <input type="hidden" name="symptom_fix" value="<?php echo $symptom_fix ?>"> <input type="hidden" name="symptom_type" value="<?php echo $symptom_type; ?>"> <input type="hidden" name="memo" value="<?php echo $memo; ?>"> <input type="hidden" name="staff" value="<?php echo $staff; ?>"> <input type="submit" value="確定"> </form> <br> <form action="health_use_register.php" method="post"> <input type="hidden" id="today" name="date" value="<?php echo $date; ?>"> <input type="hidden" id="time" name="entry_time" value="<?php echo $entry_time; ?>"> <input type="hidden" name="exit_time" value="<?php echo $exit_time; ?>"> <input type="hidden" name="student_num" value="<?php echo $student_num; ?>"> <input type="hidden" name="student_name" value="<?php echo $student_name; ?>"> <input type="hidden" name="gender" value="1" value="<?php echo $gender; ?>"> <input type="hidden" name="student_teacher" value="<?php echo $student_teacher; ?>"> <input type="hidden" name="symptom" value="<?php echo $symptom; ?>"> <input type="hidden" name="symptom_time" value="<?php echo $symptom_time; ?>"> <input type="hidden" name="symptom_cause" value="<?php echo $symptom_cause; ?>"> <input type="hidden" name="taiou" value="<?php echo $taiou; ?>"> <input type="hidden" name="symptom_fix" value="<?php echo $symptom_fix ?>"> <input type="hidden" name="symptom_type" value="<?php echo $symptom_type; ?>"> <input type="hidden" name="memo" value="<?php echo $memo; ?>"> <input type="hidden" name="staff" value="<?php echo $staff; ?>"> <input type="submit" value="編集"> </form> </body> </html>
よろしくお願いします!!
回答4件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/12/14 02:55 編集
2018/12/18 05:18