SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Hybrid View

  1. #1
    SitePoint Zealot
    Join Date
    May 2008
    0 Post(s)
    0 Thread(s)

    Multiple Radio Button Handling

    Hi folks,

    New day, new problem. I've been pondering with this problem for ages.
    Assume that I have a table, with four columns and x rows, with x being the number of comments you have waiting in a moderation queue. In column 1, you have the comment, column 2 an approve button, column 3 a reject, and column 4 a 'Flag as Spam' button.
    Now, that could either be done as a series of checkboxes, or, a more UI friendly way, as a Radio Button handling. But, Radio Buttons are bound together by the name field, which PHP also uses for it's processing!
    So, how can I get all three radio buttons mutually exclusive, and let PHP handle the lot? It's been suggest the radio button name be like so: commentid, but, how can PHP handle these, not knowing what they are going to be?

  2. #2
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Philadephia, PA
    1 Post(s)
    0 Thread(s)
    Quote Originally Posted by adamcoppard View Post
    but, how can PHP handle these, not knowing what they are going to be?
    Look at the $_POST array. You don't need to know what's in an array to loop through it.

    HTML Code:
    <form action="moderate.php" method="post">
    <input type="radio" name="moderate_1" value="approve"> Approve 
    <input type="radio" name="moderate_1" value="reject"> Reject
    <input type="radio" name="moderate_1" value="spam"> Mark as Spam
    Comment 1
    <input type="radio" name="moderate_2" value="approve"> Approve 
    <input type="radio" name="moderate_2" value="reject"> Reject
    <input type="radio" name="moderate_2" value="spam"> Mark as Spam
    Comment 2
    PHP Code:
    foreach ($_POST as $key => $value) {
      if (
    strpos($key"moderate_") !== false) {
    $id str_replace("moderate_"""$key);
        if (
    $value == "approve") {
        } else if (
    $value "reject") {
        } ...


Posting Permissions

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