| Viewed 103 times

How know which radio button is selected via PHP?


How know which radio button is selected via PHP?

1 Answer
Mohammad Qandeel
Answered
3

The radio button is used to force the user to choose only one option from a selection
so for example when you complete a payment, you are asked to choose only one payment method from the payment method group

Example 

<form method="GET">
    <label for="f-check">MasterCard
        <input type="radio" name="Payment" value="1" id="f-check">
    </label>
    <label for="s-check">Paypal
        <input type="radio" name="Payment" value="2" id="s-check">
    </label>
    <input type="submit">
</form>

input tag need these attributes to work

  • type  =radio
  • name=any-name -be sure to choose one name for the same group
  • value=each individual element has a different value

 

after that, we will handle the form request when the user submits the form using PHP

add below code to the same HTML form page

<?php
    if(isset($_GET['Payment']))
    {
        $Payment=$_GET['Payment'];
        echo $Payment;
    }
?>