忍者ブログ

からすまる日誌

20200124pm03 tests_form.php

×

[PR]上記の広告は3ヶ月以上新規記事投稿のないブログに表示されています。新しい記事を書く事で広告が消えます。

20200124pm03 tests_form.php

ダイナミックテーブルから入力してはいけませんよ
静的なほうからおさえるのですよ
 
students_form.phpを別名保存して
tests_form.php
にする
もろもろ変更
 
・labelでくくる
・input typeはradio
・nameはそろえる
・idは変える
・valueを入れる
 
valueは「1学期」「中間」とかでももちろん良いのだが、
数字にしておくとあとあと楽らしい
数字である前提のものは整数化される便利なイントバルというものがあるらしい。
それでサニタイズがめっちゃらくになるらしい
数字は悪さができないので。
文字列チェックとなると少々こみいるので、
先生はvalueは数字を使うらしい
 
なるべく数値を送信させると安全とのこと
それを見越してDBの方もint型になってますしね。 
--->tests_form.php
 
<!DOCTYPE html>
<html lang="ja">
<head>
 <meta charset="utf-8">
 <title>テスト登録</title>
 <link rel="stylesheet" href="css/style.css">
 <script src="../jquery-3.4.1.min.js"></script>
</head>
<body>
 <div id="container">
  <h1>新規テストの登録</h1>
  <form action="insert_t.php" method="post">
  
  <!--4行2列-->
  <table>
   <tr>
    <th><label for="t_name">テスト名</label></th>
    <td><input type="text" name="t_name" id="t_name"></td>
   </tr>
   <tr>
    <th>学年</th>
    <td>
     <label>
       1年<input type="radio" name="grade" id="grade1" value="1" checked="checked">
     </label>
     <label>
       2年<input type="radio" name="grade" id="grade2" value="2">
     </label>
     <label>
       3年<input type="radio" name="grade" id="grade3" value="3">
     </label>
    </td>
   </tr>
   <tr>
    <th>学期</th>
    <td>
     <label>
      1学期<input type="radio" name="trem" id="trem1" value="1" checked="checked">
     </label>
     <label>
      2学期<input type="radio" name="trem" id="trem2" value="2">
     </label>
     <label>
      3学期<input type="radio" name="trem" id="trem3" value="3">
     </label>
    </td>
   </tr>
   <tr>
    <th>テストの種類</th>
    <td>
     <label>
       中間<input type="radio" name="type" id="type1" value="1" checked="checked">
     </label>
     <label>
       期末<input type="radio" name="type" id="type2" value="2">
     </label>
     <label>
      その他<input type="radio" name="type" id="type3" value="3">
     </label>
    </td>
   </tr>
  
  </table>
  <p><button type="submit">登録</button></p>
  
  </form>
  <p id="msg"></p>
 </div>
 <script src="js/form.js"></script>
</body>
</html>
 
--->insert_t.php
<?php
 //var_dump($_POST);//受け取れているかのテスト
 print_r($_POST);//どっちの記述でもよろしい
?>

var_dump($_POST);
でやった結果
array(4) { ["t_name"]=> string(15) "タコテスト" ["grade"]=> string(1) "2" ["trem"]=> string(1) "2" ["type"]=> string(1) "2" }
 
print_r($_POST);
Array ( [t_name] => クエテスト [grade] => 3 [trem] => 3 [type] => 1 )
PR

コメント

ブログ内検索

カレンダー

03 2025/04 05
S M T W T F S
1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30