retaiing values when resubmitting a page

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Ian Davies

    #1

    retaiing values when resubmitting a page

    Hello

    does anyone know how I can retain values of a radio button and text in a
    text box on a page when I use $_SERVER['PHP_SELF'] to requery a page? Im
    sure Ive seen this done before but cant find the code

    Thanks
    Ian


  • David Haynes

    #2
    Re: retaiing values when resubmitting a page

    Ian Davies wrote:[color=blue]
    > Hello
    >
    > does anyone know how I can retain values of a radio button and text in a
    > text box on a page when I use $_SERVER['PHP_SELF'] to requery a page? Im
    > sure Ive seen this done before but cant find the code
    >
    > Thanks
    > Ian
    >
    >[/color]

    The radio button and text are contained within a <form></form> tag set.
    The <form> tag will have either method="GET" or method="POST"

    If method="GET", you can read back the values using:
    $foo = $_GET['foo'] where 'foo' is the name of your radio selector or
    text field.

    If method="POST", you can read back the values using:
    $foo = $_POST['foo'];

    -david-

    Comment

    • dimo414

      #3
      Re: retaiing values when resubmitting a page

      inside the tag for the textarea, the value attribute should be set to a
      snippet of php which echo's (or prints) the value of the posted
      variables. If nothing has been submitted, then nothing will be echoed,
      and the box will appear empty. if something was submitted, it will be
      echoed back into the box. A similar idea applies to radio and
      checkboxes, but it's SLIGHTLY more dificult because you have to
      determine (using if conditionals) which button it should be set to.

      Comment

      • Ian Davies

        #4
        Re: retaiing values when resubmitting a page

        thanks
        I found a solution. posted below incase anyone else is interested

        at top of page
        session_start() ;
        $_SESSION['mytextbox'] = trim($_POST['mytextbox']);
        $_SESSION['myradiobutton'] = trim($_POST['myradiobutton']);

        for the textbox
        input name="mytextbox " type="text" value="<?php echo
        $_SESSION['mytextbox'];?>"

        for the radiobutton
        input <?php if (!(strcmp($_SES SION['myradiobutton'],"1"))) {echo "CHECKED";}
        ?> name="myradiobu tton" type="radio" value="yourchec kedvaluehere"

        ian


        "dimo414" <dimo414@gmail. com> wrote in message
        news:1148936810 .408821.112400@ j33g2000cwa.goo glegroups.com.. .[color=blue]
        > inside the tag for the textarea, the value attribute should be set to a
        > snippet of php which echo's (or prints) the value of the posted
        > variables. If nothing has been submitted, then nothing will be echoed,
        > and the box will appear empty. if something was submitted, it will be
        > echoed back into the box. A similar idea applies to radio and
        > checkboxes, but it's SLIGHTLY more dificult because you have to
        > determine (using if conditionals) which button it should be set to.
        >[/color]


        Comment

        Working...