Radio Buttons with PHP Form Handling

后端 未结 4 430
暖寄归人
暖寄归人 2020-12-30 09:19

I have a basic form that I am submitting using some basic PHP. I have the form submission working great, except that I have a radio button (for preferred method of contact)

相关标签:
4条回答
  • 2020-12-30 09:39

    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>
    
    0 讨论(0)
  • 2020-12-30 09:44

    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>
    
    0 讨论(0)
  • 2020-12-30 09:55
    <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".
    
    0 讨论(0)
  • 2020-12-30 09:57

    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>
    
    0 讨论(0)
提交回复
热议问题