problem passing radio button value between pages

Discussion in 'PHP' started by clouting, Jan 25, 2008.

  1. #1
    hey folks,

    have an annoying problem. I have a form which spreads over 2 pages. i want to pass all the values from the fisrt page of the form to the second. it was easy to pass the 'text area' values using a simple
    echo "$value"
    PHP:
    code.
    However i need to pass the value of a checked radio button so that the same button is checked on the next page. Does any1 know how to do this??

    i am kind of a novice with PHP so i apologise if it is really obvious!!

    thanks in advance
    clouting
    ..........
     
    clouting, Jan 25, 2008 IP
  2. sharqi

    sharqi Guest

    Messages:
    105
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #2
    pass the value ($value) to the second page as normal..

    if ($value == $whatever) {
    echo "this is my html";
    }
    else if ($value == $whatever2) {
    echo "this is my html";
    }
    else {
    echo "this is some other html";
    }

    Or you can use a switch
    www.php.net/switch
     
    sharqi, Jan 25, 2008 IP
  3. xxKillswitch

    xxKillswitch Peon

    Messages:
    331
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #3
    You are using post to submit the values to another page?

    You should be able to access the values with $_POST['radio'];

    Assuming...

    <input type="radio" name="radio" value="1">Yes
    <input type="radio" name="radio" value="0">No

    That should be it really. You can also try using $_REQUEST, but it is less secure than $_POST.
     
    xxKillswitch, Jan 25, 2008 IP
  4. Kaizoku

    Kaizoku Well-Known Member

    Messages:
    1,261
    Likes Received:
    20
    Best Answers:
    1
    Trophy Points:
    105
    #4
    $_REQUEST is for both $_GET and $_POST globals.
     
    Kaizoku, Jan 25, 2008 IP
  5. sharqi

    sharqi Guest

    Messages:
    105
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #5
    He is trying to take the post data and pre select a radio button on a second form page - based on the post data
     
    sharqi, Jan 25, 2008 IP
  6. fairuz.ismail

    fairuz.ismail Peon

    Messages:
    232
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    0
    #6
    is this what you want??

    let say you have $_REQUEST['myradio'] from the first page.

    <form>
    <input type="radio" name="fruit" value="apples" style="border-width: 0px;" <?php if($_REQUEST['myradio']) echo "checked=\"checked\""; ?>> Apples
    </form>
     
    fairuz.ismail, Jan 26, 2008 IP
  7. clouting

    clouting Guest

    Messages:
    120
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #7
    hi..thanks every1 for your help.
    I will try your suggestions and see how they go.

    thanks a lot!!!!
     
    clouting, Jan 27, 2008 IP
  8. clouting

    clouting Guest

    Messages:
    120
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #8
    right.

    iam using the code posted by fairuz.ismail

    sorry for an obviousquestion but where exactly do i put the $_REQUEST['myradio'] on the form?? i know its on the first page buti just need to know howi add the code.

    thanks in advance
     
    clouting, Jan 28, 2008 IP