回答編集履歴
1
修正
    
        answer	
    CHANGED
    
    | @@ -1,49 +1,30 @@ | |
| 1 1 | 
             
            汎用的にやるならこんな感じ
         | 
| 2 | 
            +
            (ちょっと見やすく書き換えました)
         | 
| 2 3 | 
             
            ```PHP
         | 
| 3 4 | 
             
            <?php 
         | 
| 4 | 
            -
            function h($str){
         | 
| 5 | 
            -
              return htmlspecialchars($str);
         | 
| 6 | 
            -
            }
         | 
| 7 5 |  | 
| 8 6 | 
             
            $text=[];
         | 
| 9 | 
            -
            $ | 
| 7 | 
            +
            $h=[];
         | 
| 10 | 
            -
            $ | 
| 8 | 
            +
            $checked=[];
         | 
| 11 | 
            -
            $student_num = filter_input(INPUT_POST,'student_num');
         | 
| 12 | 
            -
            $text["student_num"]=h($student_num);
         | 
| 13 | 
            -
            $student_name = filter_input(INPUT_POST,'student_name');
         | 
| 14 | 
            -
            $text["student_name"]=h($student_name);
         | 
| 15 | 
            -
            $student_teacher = filter_input(INPUT_POST,'student_teacher');
         | 
| 16 | 
            -
            $text["student_teacher"]=h($student_teacher);
         | 
| 17 | 
            -
            $symptom = filter_input(INPUT_POST,'symptom');
         | 
| 18 | 
            -
            $text["symptom"]=h($symptom);
         | 
| 19 | 
            -
            $symptom_time = filter_input(INPUT_POST,'symptom_time');
         | 
| 20 | 
            -
            $text["symptom_time"]=h($symptom_time);
         | 
| 21 | 
            -
            $symptom_cause = filter_input(INPUT_POST,'symptom_cause');
         | 
| 22 | 
            -
            $text["symptom_cause"]=h($symptom_cause);
         | 
| 23 | 
            -
            $taiou = filter_input(INPUT_POST,'taiou');
         | 
| 24 | 
            -
            $text["taiou"]=h($taiou);
         | 
| 25 | 
            -
            $symptom_fix = filter_input(INPUT_POST,'symptom_fix');
         | 
| 26 | 
            -
            $text["symptom_fix"]=h($symptom_fix);
         | 
| 27 | 
            -
            $memo = filter_input(INPUT_POST,'memo');
         | 
| 28 | 
            -
            $text["memo"]=h($memo);
         | 
| 29 | 
            -
            $symptom_type = filter_input(INPUT_POST,'symptom_type');
         | 
| 30 | 
            -
            $text["symptom_type"]=h($symptom_type);
         | 
| 31 | 
            -
            $entry_time = filter_input(INPUT_POST,'entry_time');
         | 
| 32 | 
            -
            $text["entry_time"]=h($entry_time);
         | 
| 33 | 
            -
            $exit_time = filter_input(INPUT_POST,'exit_time');
         | 
| 34 | 
            -
            $text["exit_time"]=h($exit_time);
         | 
| 35 | 
            -
            $staff = filter_input(INPUT_POST,'staff'); 
         | 
| 36 | 
            -
            $text["staff"]=h($staff);
         | 
| 37 9 |  | 
| 10 | 
            +
            $list=["date","student_num","student_name","student_teacher","symptom",
         | 
| 11 | 
            +
                   "symptom_time","symptom_cause","taiou","symptom_fix","memo",
         | 
| 38 | 
            -
             | 
| 12 | 
            +
                   "symptom_type","entry_time","exit_time","staff"
         | 
| 39 | 
            -
            $gender = filter_input(INPUT_POST,'gender');
         | 
| 40 | 
            -
             | 
| 13 | 
            +
                   ];
         | 
| 41 14 |  | 
| 42 | 
            -
            $ | 
| 15 | 
            +
            foreach($list as $val){
         | 
| 43 | 
            -
            $ | 
| 16 | 
            +
              $text[$val]=filter_input(INPUT_POST,$val);
         | 
| 44 | 
            -
            $ | 
| 17 | 
            +
              $h[$val]=htmlspecialchars($text[$val]);
         | 
| 18 | 
            +
            }
         | 
| 45 19 |  | 
| 20 | 
            +
            $checked=[
         | 
| 21 | 
            +
              "gender"=>[1=>"",2=>""],
         | 
| 22 | 
            +
              "symptom_type"=>["外科"=>"","内科"=>"","その他"=>""],
         | 
| 23 | 
            +
              ];
         | 
| 46 24 |  | 
| 25 | 
            +
            foreach(array_keys($checked) as $val){
         | 
| 26 | 
            +
              $checked[$val][filter_input(INPUT_POST,$val)]=" checked";
         | 
| 27 | 
            +
            }
         | 
| 47 28 |  | 
| 48 29 | 
             
            print <<<eof
         | 
| 49 30 | 
             
            <h3>保健室利用メモ</h3>
         | 
| @@ -51,23 +32,23 @@ | |
| 51 32 | 
             
            <table>
         | 
| 52 33 | 
             
            <tr>
         | 
| 53 34 | 
             
            <th>日付:</th>
         | 
| 54 | 
            -
            <td><input type="date" id="today" name="date" value="{$ | 
| 35 | 
            +
            <td><input type="date" id="today" name="date" value="{$h["date"]}"></td>
         | 
| 55 36 | 
             
            </tr>
         | 
| 56 37 | 
             
            <tr>
         | 
| 57 38 | 
             
            <th>入室時間:</th>
         | 
| 58 | 
            -
            <td><input type="time" id="time" name="entry_time" value="{$ | 
| 39 | 
            +
            <td><input type="time" id="time" name="entry_time" value="{$h["entry_time"]}"></td>
         | 
| 59 40 | 
             
            </tr>
         | 
| 60 41 | 
             
            <tr>
         | 
| 61 42 | 
             
            <th>退出時間:</th>
         | 
| 62 | 
            -
            <td><input type="time" id="time" name="exit_time" value="{$ | 
| 43 | 
            +
            <td><input type="time" id="time" name="exit_time" value="{$h["exit_time"]}"></td>
         | 
| 63 44 | 
             
            </tr>
         | 
| 64 45 | 
             
            <tr>
         | 
| 65 46 | 
             
            <th>学籍番号:</th>
         | 
| 66 | 
            -
            <td><input type="text" name="student_num" placeholder="16XX0101" value="{$ | 
| 47 | 
            +
            <td><input type="text" name="student_num" placeholder="16XX0101" value="{$h["student_num"]}"></td>
         | 
| 67 48 | 
             
            </tr>
         | 
| 68 49 | 
             
            <tr>
         | 
| 69 50 | 
             
            <th>氏名:</th>
         | 
| 70 | 
            -
            <td><input type="text" name="student_name" placeholder="電子太郎" value="{$ | 
| 51 | 
            +
            <td><input type="text" name="student_name" placeholder="電子太郎" value="{$h["student_name"]}"></td>
         | 
| 71 52 | 
             
            </tr>
         | 
| 72 53 | 
             
            <tr>
         | 
| 73 54 | 
             
            <th>性別:</th>
         | 
| @@ -79,27 +60,27 @@ | |
| 79 60 | 
             
            </tr>
         | 
| 80 61 | 
             
            <tr>
         | 
| 81 62 | 
             
            <th>担任:</th>
         | 
| 82 | 
            -
            <td><input type="text" name="student_teacher" value="{$ | 
| 63 | 
            +
            <td><input type="text" name="student_teacher" value="{$h["student_teacher"]}"></td>
         | 
| 83 64 | 
             
            </tr>
         | 
| 84 65 | 
             
            <tr>
         | 
| 85 66 | 
             
            <th>症状:</th>
         | 
| 86 | 
            -
            <td><input type="text" name="symptom"  value="{$ | 
| 67 | 
            +
            <td><input type="text" name="symptom"  value="{$h["symptom"]}"></td>
         | 
| 87 68 | 
             
            </tr>
         | 
| 88 69 | 
             
            <tr>
         | 
| 89 70 | 
             
            <th>いつから:</th>
         | 
| 90 | 
            -
            <td><input type="text" name="symptom_time" value="{$ | 
| 71 | 
            +
            <td><input type="text" name="symptom_time" value="{$h["symptom_time"]}"></td>
         | 
| 91 72 | 
             
            </tr>
         | 
| 92 73 | 
             
            <tr>
         | 
| 93 74 | 
             
            <th>原因は?:</th>
         | 
| 94 | 
            -
            <td><input type="text" name="symptom_cause" value="{$ | 
| 75 | 
            +
            <td><input type="text" name="symptom_cause" value="{$h["symptom_cause"]}"></td>
         | 
| 95 76 | 
             
            </tr>
         | 
| 96 77 | 
             
            <tr>
         | 
| 97 78 | 
             
            <th>対応:</th>
         | 
| 98 | 
            -
            <td><input type="text" name="taiou" value="{$ | 
| 79 | 
            +
            <td><input type="text" name="taiou" value="{$h["taiou"]}"></td>
         | 
| 99 80 | 
             
            </tr>
         | 
| 100 81 | 
             
            <tr>
         | 
| 101 82 | 
             
            <th>処置:</th>
         | 
| 102 | 
            -
            <td><input type="text" name="symptom_fix" value="{$ | 
| 83 | 
            +
            <td><input type="text" name="symptom_fix" value="{$h["symptom_fix"]}"></td>
         | 
| 103 84 | 
             
            </tr>
         | 
| 104 85 | 
             
            <tr>
         | 
| 105 86 | 
             
            <th>症状種別:</th>
         | 
| @@ -111,11 +92,11 @@ | |
| 111 92 | 
             
            </tr>
         | 
| 112 93 | 
             
            <tr>
         | 
| 113 94 | 
             
            <th>メモ:</th>
         | 
| 114 | 
            -
            <td><textarea name="memo">{$ | 
| 95 | 
            +
            <td><textarea name="memo">{$h["memo"]}</textarea></td>
         | 
| 115 96 | 
             
            </tr>
         | 
| 116 97 | 
             
            <tr>
         | 
| 117 98 | 
             
            <th>対応者:</th>
         | 
| 118 | 
            -
            <td><input type="text" name="staff" value="{$ | 
| 99 | 
            +
            <td><input type="text" name="staff" value="{$h["staff"]}"></td>
         | 
| 119 100 | 
             
            </tr>
         | 
| 120 101 | 
             
            </table>
         | 
| 121 102 | 
             
            <input type="submit" value="確定">
         | 
| @@ -124,5 +105,4 @@ | |
| 124 105 | 
             
            </html>
         | 
| 125 106 |  | 
| 126 107 | 
             
            eof;
         | 
| 127 | 
            -
            ?>
         | 
| 128 108 | 
             
            ```
         | 
