Results 1 to 4 of 4
  1. #1
    Join Date
    Aug 2004
    Posts
    82

    Unanswered: Radio Buttons and $_POST

    I am making an online RPG using PHP and I got stuck making a crime module. Basically, I have some radio buttons which are grouped (See below) but have different values. When the user presses submit it goes to another php. (So I need to use the $_POST function) Is there a way for this "other" php document to know which radio button was checked. Hopefully this code will help you understand:

    The First PHP doc:

    PHP Code:
    <html>
    <
    form name="CommitCrime" action="commitcrime.php" method="post">
    <
    table border="1">
    <
    tr>
    <
    td>Crime</td>
    <
    td>     </td>
    </
    tr>
    <
    tr>
    <
    td>Steal from the Medievil Times</td>
    <
    td><input type="radio" name="group1" value="Newspaper"></td>
    </
    tr>
    <
    tr>
    <
    td>Steal from the Trade Centre</td>
    <
    td><input type="radio" name="group1" value="TradeCentre"></td>
    </
    tr>
    <
    tr>
    <
    td>Rob someones home</td>
    <
    td><input type="radio" name="group1" value="House"></td>
    </
    tr>
    <
    tr>
    <
    td>Scavenge in bins</td>
    <
    td><input type="radio" name="group1" value="Scavenge"></td>
    </
    tr>
    <
    tr>
    <
    td>Pickpocket a trader</td>
    <
    td><input type="radio" name="group1" value="Pickpocket"></td>
    </
    tr>
    </
    table>
    <
    br><input type="submit" name="submit" value="COMMIT CRIME!"><br>
    </
    form>
    </
    html
    Then all the other doc does is writes the info to my database!


    Any help will be great,


    Thanks,


    ~Jordan

  2. #2
    Join Date
    Apr 2005
    Location
    Baltimore, MD
    Posts
    297
    PHP Code:
    //included in commitcrime.php
    ...
    $checkedRadioButton $_POST['group1'];
    ... 

  3. #3
    Join Date
    Jan 2004
    Location
    India
    Posts
    168
    Quote Originally Posted by jwman
    I am making an online RPG using PHP and I got stuck making a crime module. Basically, I have some radio buttons which are grouped (See below) but have different values. When the user presses submit it goes to another php. (So I need to use the $_POST function) Is there a way for this "other" php document to know which radio button was checked. Hopefully this code will help you understand:

    The First PHP doc:

    PHP Code:
    <html>
    <
    form name="CommitCrime" action="commitcrime.php" method="post">
    <
    table border="1">
    <
    tr>
    <
    td>Crime</td>
    <
    td>     </td>
    </
    tr>
    <
    tr>
    <
    td>Steal from the Medievil Times</td>
    <
    td><input type="radio" name="group1" value="Newspaper"></td>
    </
    tr>
    <
    tr>
    <
    td>Steal from the Trade Centre</td>
    <
    td><input type="radio" name="group1" value="TradeCentre"></td>
    </
    tr>
    <
    tr>
    <
    td>Rob someones home</td>
    <
    td><input type="radio" name="group1" value="House"></td>
    </
    tr>
    <
    tr>
    <
    td>Scavenge in bins</td>
    <
    td><input type="radio" name="group1" value="Scavenge"></td>
    </
    tr>
    <
    tr>
    <
    td>Pickpocket a trader</td>
    <
    td><input type="radio" name="group1" value="Pickpocket"></td>
    </
    tr>
    </
    table>
    <
    br><input type="submit" name="submit" value="COMMIT CRIME!"><br>
    </
    form>
    </
    html
    Then all the other doc does is writes the info to my database!


    Any help will be great,


    Thanks,


    ~Jordan
    You can get the value of the radio button selected using the post method.
    eg:

    $radio_button = $_POST['group1'];

    Hope this solves you problem...
    If you need more help get back to us.

    Regards
    Rajesh
    Freelance and Technology Consultant
    -------------------
    Dreams are for ever
    -------------------

  4. #4
    Join Date
    Aug 2004
    Posts
    82
    Cheers for that, works perfectly!

Posting Permissions

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