grouping and adding form values

Discussion in 'PHP' started by passingTime, Feb 9, 2012.

  1. #1
    Hi, I would like to know if there's a way to quickly collect and sort form data, then use that data in an if statement. I've tried for a while now and i just can't seem to figure it out.

    I would like to do this with radio buttons. Hopefully this will make it clear:
    
    <?php
    
    if (isset($_POST['submit'])) 
    {
    // I don't know how to do this but maybe something like
    
    // if $_POST values == "Yes"
    // put them into an array
    // then count how many are in the array, e.g. 2 if 2 "Yes" radio buttons are selected
    
    $count = count($array) . " Yes values selected";
    echo $count;
    
    //else if do the same for "No" values
    
    // hopefully this is understandable
    }
    
    ?>
    
    <!-- i want to take these values and group them, so all the "Yes" values selected together and the "no" values together -->
    <form method="post" action="">
    
    <input type="radio" name="first" value="Yes" /> 
    <input type="radio" name="first" value="No" /> 
    
    <input type="radio" name="second" value="Yes" /> 
    <input type="radio" name="second" value="No" /> 
    
    <input type="submit" name="submit">
    </form>
    
    Code (markup):

     
    passingTime, Feb 9, 2012 IP