SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Addict
    Join Date
    May 2006
    Posts
    349
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Basic Radio buttons with php help

    Hello, I know how to make forms with php. Not quite sure how to
    include a radio button function.

    For instance. Maybe someones picking a color. This in the html page.
    Red:
    <input type="radio" checked="checked"
    name="color" value="male">
    Blue:
    <input type="radio" checked="checked"
    name="color" value="male">
    Purpleinput type="radio" checked="checked"
    name="color" value="male">

    Do I need a different $ in the php for each color?
    How will only the one picked be sent to the php form?

    Thank you very much!!

  2. #2
    I meant that to happen silver trophybronze trophy Raffles's Avatar
    Join Date
    Sep 2005
    Location
    Tanzania
    Posts
    4,662
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Since they're radio buttons, you can only have one checked (checked="checked") to begin with. And they all have to have different values, otherwise you won't know what it was. So for the red one, give it value="red" and so on. Better show some code:
    HTML Code:
    <form action="colour.php" method="post">
    Red: <input type="radio" name="colour" value="red" />
    Green: <input type="radio" name="colour" value="green" />
    Blue: <input type="radio" name="colour" value="blue" />
    <input type="submit" />
    </form>
    In colour.php:
    PHP Code:
    <?php $colour $_POST['colour']; ?>

  3. #3
    SitePoint Wizard
    Join Date
    Jan 2001
    Location
    Grand Rapids, MI
    Posts
    1,284
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    One thing to note, is that if a checkbox is not checked, no value is passed when you submit the form. So in your example above, $_POST['colour'], would be empty if no value was checked. Just something to keep in mind.

  4. #4
    SitePoint Addict
    Join Date
    May 2006
    Posts
    349
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Got it, Thanks!
    Last edited by 1Jen; Sep 29, 2006 at 12:46.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •