PHP HTML Form radio button Example

PHP HTML Form radio button Example

make a file “php-html-form-radio-button-example.php" then copy & paste blow code.

php-html-form-radio-button-example.php

<?php

   if(isset($_POST['BtnSubmit']))
   {
      echo "<h3>Your form data as bellow</h3>";
      echo "</br>Your Name :{$_POST['FullName']}";
      echo "</br>Your are :{$_POST['YourGender']}";
      echo "<hr>";
   }

?>

<h3>PHP HTML Form radio button Example</h3>

<form name="UserInformationForm" method="POST" action="#">
      Enter Your Full Name :
      <input name="FullName" type="text" value="<?php echo $_POST['FullName']; ?>"><br/><br/>
      You are :
      <input name="YourGender" type="radio" value="male" <?php if($_POST['YourGender']=="male") echo "checked=checked"; ?> > Male
      <input name="YourGender" type="radio" value="female" <?php if($_POST['YourGender']=="female") echo "checked=checked"; ?>> Female
      <br/><br/>
      <input name="BtnSubmit" type="submit" value="Submit">
</form>

Fire-up your favorite browser to see the effect of a blank HTML form with radio button in PHP "http://localhost/blog/php-html-form-radio-button-example.php". Browser output should look like as follows:

 

Now fill-up the HTML form and get submitted data in PHP "http://localhost/blog/php-html-form-radio-button-example.php". Browser output should look like as follows:

 

Related Tutorial Examples

  1. PHP HTML Form textarea Example
  2. PHP HTML Form Input Example
  3. HTML Form Example in PHP
  4. PHP HTML Form select box Example
  5. 20 steps to make CakePHP Blog Project
  6. MySQL IF() Function Boolean Value Example
  7. MySQL strcmp() Function Number Value Example
  8. MySQL concat function SQL Example
  9. Arithmetic operators in SQL Command MySQL Example
  10. PERL Example: Use of Arrays in PERL

3 comments:

  1. How do you get the radio input to run a PHP method without having to push the SUBMIT button? I know that it is with AJAX, but I am not sure how to implement.

    ReplyDelete
    Replies
    1. Paul agree with you. You will get Radio input after submit button had pushed. Since Ajax works on partial page refresh you can have from data without submit.

      Delete
    2. Bellow example may be helpful:

      http://stackoverflow.com/questions/15814369/getting-radio-button-value-and-sending-through-ajax-to-php

      Delete

leave your comments here..