php select|phpでセレクトボックスを作って値を受け取る方法

スポンサーリンク

はじめに

phpでフォームのセレクト要素を受け取る方法。
けっこう基本だと思うけど忘れがち。

html

html側でセレクト部分だけ抜粋すると

<select name="frameRate" id="frameRate">
                <?php
                for($i=1;$i<10;$i++){
                    print('<option value="' .$i. '">'.$i.'</option>');
                }
                ?>
</select>

php

次にphpのセレクト部分の値の受取だけ抜粋。
$_POST['htmlで指定したname']で値を取得。

$frameRate = $_POST['frameRate'];

f:id:shangtian:20190216101118p:plain f:id:shangtian:20190216101120p:plain

全体の全体のコード

gist9e014b99c46b7fa787bd9eec0107ed0f

gistef9e5399dd0d8d98cf124e32670541d4