Radio Buttons with PHP Form Handling

筅森魡賤 提交于 2019-11-28 08:36:14
<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>

Easy! Just add a value to your radio buttons.

<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>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!