PHP ရှိ Radio Button များ

ယခု PHP တွင် radio button များနှင့် အလုပ်လုပ်ပုံကို လေ့လာကြပါစို့။ ကျွန်ုပ်တို့၏ form ထဲတွင် ရွေးချယ်စရာ button အချို့ ပြုလုပ်ကြမည်။

html<form action="" method="GET">
  <input type="radio" name="radio" value="1">
  <input type="radio" name="radio" value="2">
  <input type="radio" name="radio" value="3">
  <input type="submit">
</form>

Form ကိုတင်ပြီးနောက် $_GET array ထဲတွင် ရွေးချယ်ထားသော radio button ၏ value attribute တန်ဖိုး ပါဝင်ပါမည်။ တစ်ခုမှ မရွေးချယ်ထားပါက null ဖြစ်ပါမည်။

html<?php
  var_dump($_GET['radio']); // '1', '2', '3' သို့မဟုတ် null
?>

Radio button များနှင့် အလုပ်လုပ်စဉ်တွင် checkbox များတွင်ကြုံရသော ပြဿနာနှင့် အတူတူပင် ကြုံတွေ့ရပါမည်။ ထိုပြဿနာကိုဖြေရှင်းရန် hidden input တစ်ခုကို ထည့်သွင်းကြပါစို့။

html<form action="" method="GET">
  <input type="hidden" name="radio" value="0">
  <input type="radio"  name="radio" value="1">
  <input type="radio"  name="radio" value="2">
  <input type="radio"  name="radio" value="3">
  <input type="submit">
</form>

သို့မဟုတ် hidden input ထည့်ရန်မလိုဘဲ radio button တစ်ခုခုကို ပုံသေအမှတ်အသားပြုထားနိုင်ပါသည်။

html<form action="" method="GET">
  <input type="radio" name="radio" value="1" checked>
  <input type="radio" name="radio" value="2">
  <input type="radio" name="radio" value="3">
  <input type="submit">
</form>
Задание 1

Radio button နှစ်ခုကို အသုံးပြု၍ အသုံးပြုသူ၏ လိင် (gender) ကို မေးမြန်းပါ။ ရလဒ်ကို စကရင်ပေါ်တွင် ပြသပါ။