Radio Buttons with PHP Form Handling Radio Buttons with PHP Form Handling php php

Radio Buttons with PHP Form Handling


<div class="field form-inline radio">  <label class="radio" for="txtContact">Preferred Method of Contact</label>  <input class="radio" type="radio" name="contact" value="email" checked /> <span>Email</span>  <input class="radio" type="radio" name="contact" value="phone" /> <span>Phone</span></div>

Note the added value attribute.

And the PHP:

$contact = $_POST['contact']//Will return either "email" or "phone".


You radios need values:

  <input class="radio" type="radio" value="email" name="contact" checked /> <span>Email</span>  <input class="radio" type="radio" value="phone" name="contact" /> <span>Phone</span>


Just give your radio inputs a value-attribute. This is what will get submitted via POST. You can then access it via $_POST['nameofradio']

  <input class="radio" type="radio" name="contact" value="Email" checked /> <span>Email</span>  <input class="radio" type="radio" name="contact" value="Phone" /> <span>Phone</span>