How to get data from a radio button

The HTML for three radio buttons in a group

      <input type="radio" id="visa" name="card_type" checked />Visa<br>
      <input type="radio" id="mastercard" name="card_type" />MasterCard<br>
      <input type="radio" id="discover" name="card_type" />Discover<br>
      

The PHP to access a radio button group

      <?php
      $card_type = filter_input(INPUT_POST, 'card_type');
      ?>
      

The PHP to add a default value for a group with no default button

      <?php
      $card_type = filter_input(INPUT_POST, 'card_type'); 
      if ($card_type == NULL) { 
        $card_type = 'unknown'; 
      }
      ?>
      

Back