can someone please tell me how i would get the selected radio buttons info to email

Discussion in 'PHP' started by bluebirdjc, Nov 26, 2007.

  1. #1
    here is the radio buttons they could select from

    <input type="radio" value="4" name="2ndq">Excellent <input type="radio" value="3" name="2ndq">Good <input type="radio" value="2" name="2ndq">Average <input type="radio" value="1" name="2ndq">Poor
     
    bluebirdjc, Nov 26, 2007 IP
  2. lounar

    lounar Peon

    Messages:
    43
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    could u plz more specific on what u need?
     
    lounar, Nov 26, 2007 IP
  3. bluebirdjc

    bluebirdjc Guest

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    sorry the html above is part of a questionairre i have created

    whatever one the user chooses i want to send to email i have a form for doing this and here is the php code for the questionairre

    html>
    <head>
    <title>Results of questionairre</title>
    </head>

    <body>
    <?php
    if(isset($_POST['submit'])) {
    $to = "J.K.Childs@cs.cardiff.ac.uk";
    $subject = "Questionairre subbmision";
    $ctaken_field = $_POST['course'];
    $second_question = $_POST['2ndq'];
    $third_question = $_POST['3rdq'];
    $Name_field = $_POST['firstname'];
    foreach($_POST['Mailing-List'] as $value) {
    $check_msg .= "Checked: $value\n";
    }
    $fifth_question = $_POST['5thq'];
    $wh_question = $_POST['which'];
    $sixth_question = $_POST['6thq'];
    $seventh_question = $_POST['7thq'];
    $extra_field = $_POST['extra'];



    $body = "From: $subject\n Course: $ctaken_field\n Answer 2: $second_question\n Answer 3: $third_question\n Answer 4: $Name_field\n Answer 5: $mail_question\n Answer 6: $fifth_question\n Answer 7: $wh_question\n Answer 8: $sixth_question\n Answer 9: $seventh_question\n Answer 10 : $extra_field\n Message:\n $message";

    echo "Thank you for filling out this questionairre!";
    mail($to, $subject, $body);
    } else {
    echo "Sorry there was an error please go back and try again!";
    }
    ?>


    </form>
    </body>

    </html>

    as you can see the code for my shown radio buttons is

    $second_question = $_POST['2ndq'];

    however i dont thoink htis is right do you know what the correct code would be
     
    bluebirdjc, Nov 26, 2007 IP
  4. lfhost

    lfhost Peon

    Messages:
    232
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #4
    HI,

    The easiest answer is to just put the answer into the value

    
    <input type="radio" value="Excellent" name="2ndq">Excellent <input type="radio" value="Good" name="2ndq">Good <input type="radio" value="Average" name="2ndq">Average <input type="radio" value="Poor" name="2ndq">Poor
    
    PHP:
    Or you would probably best to create an array of answers.

    $answer = array();
    $answer = array(
    4 => "Excellent",
    3 => "Good",
    2 => "Average",
    1 => "Poor"
    );
    PHP:
    You would then change

    $second_question = $_POST['2ndq'];
    PHP:
    to
    $second_question = (int)$_POST['2ndq']; //make sure this is only an integer.
    $second_question = $answer[$second_question];
    PHP:
     
    lfhost, Nov 26, 2007 IP