ラジオボタンでその他を押した時にテキストボックスのデータを取得する。

とりあえずこれでPHPファイルを作って実行してみそ。

 

<html>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

<form method ="POST" action = "<?php echo "http://" . $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"]; ?>">

<input type="radio" name="flange" value="1">1<br>

<input type="radio" name="flange" value="2">2<br>

<input type="radio" name="flange" value="3">Other

<input type="text" name="flange_other"><br>

<input type="submit" value="Send!">

</form>

<?php

if(isset($_POST["flange"])){

$value = htmlspecialchars($_POST["flange"]);

if($value ==3){

$data = htmlspecialchars($_POST["flange_other"]);

}else{

$data =  htmlspecialchars($_POST["flange"]);

}

echo "送信されたデータは「".$data."」です。";

}

?>

</html>