Form in 2 steps - Preserving button radio

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

    Form in 2 steps - Preserving button radio

    Hello. Yes, already ask but no answers for this little problem.
    I've got a form and 3 steps or page for the same form. If we come back
    to the first page, the states of button radio are lost.

    First page (form1.php)
    <?
    $gender=$_POST['gender'];
    if(isset($_POST['gender'])){
    $statusm="";
    $statusf="";
    if($_POST['gender']=="M"){$statusm ="checked"}
    else{$statusf=" checked"}
    ?>

    <Form... action="form2.p hp">
    ....
    <input name="gender" type="radio" id="male" value="M"<?php echo
    $statusm
    ?>M
    <input name="gender" type="radio" id="female" value="F"<?php echo
    $statusf ?>>F
    ....
    </Form>

    Second page (form2.php)
    <?
    $Gender=$_POST['gender'];
    ?>

    <Form... action="form1.p hp">
    ....
    <input name="gender" type="hidden" id="gender" value="<? echo $gender ?
    >" />
    ....
    </Form>

    But it doesn't work!!!

    A solution could be with "session_start( )" and $_cookie but I don't
    know how to do it!

    If anybody could write me all I need on the two pages with a little
    exemple?? (The same problem come with the checkox or choise with
    dynamic menu!) Thanks, pascal

  • Arjen

    #2
    Re: Form in 2 steps - Preserving button radio

    elia schreef:
    Hello. Yes, already ask but no answers for this little problem.
    I've got a form and 3 steps or page for the same form. If we come back
    to the first page, the states of button radio are lost.
    A solution could be with "session_start( )" and $_cookie but I don't
    know how to do it!

    One way to do it.

    foreach ($_POST as $key=>$val)
    {
    echo '<input type = "hidden" name="'.htmlent ities($key).'"
    value="'.htmlen tities($val).'" />';
    }

    --
    Arjen
    http://www.hondenpage.com - Mijn site over honden

    Comment

    • elia

      #3
      Re: Form in 2 steps - Preserving button radio

      Thanks but it's doesn't work for button radio... pascal

      Comment

      • Captain Paralytic

        #4
        Re: Form in 2 steps - Preserving button radio

        On 22 Feb, 07:45, "elia" <jos...@pcl.chw rote:
        Hello. Yes, already ask but no answers for this little problem.
        I've got a form and 3 steps or page for the same form. If we come back
        to the first page, the states of button radio are lost.
        >
        First page (form1.php)
        <?
        $gender=$_POST['gender'];
        if(isset($_POST['gender'])){
        $statusm="";
        $statusf="";
        if($_POST['gender']=="M"){$statusm ="checked"}
        else{$statusf=" checked"}
        ?>
        >
        <Form... action="form2.p hp">
        ...
        <input name="gender" type="radio" id="male" value="M"<?php echo
        $statusm
        ?>M
        <input name="gender" type="radio" id="female" value="F"<?php echo
        $statusf ?>>F
        ...
        </Form>
        >
        Second page (form2.php)
        <?
        $Gender=$_POST['gender'];
        ?>
        >
        <Form... action="form1.p hp">
        ...
        <input name="gender" type="hidden" id="gender" value="<? echo $gender ?>" />
        >
        ...
        </Form>
        >
        But it doesn't work!!!
        >
        A solution could be with "session_start( )" and $_cookie but I don't
        know how to do it!
        >
        If anybody could write me all I need on the two pages with a little
        exemple?? (The same problem come with the checkox or choise with
        dynamic menu!) Thanks, pascal
        When re-writing the button code on form1 include CHECKED on the one
        that should be selected

        Comment

        • Arjen

          #5
          Re: Form in 2 steps - Preserving button radio

          elia schreef:
          Thanks but it's doesn't work for button radio... pascal
          offcourse it does.


          on page 1
          echo '<input type = "radio name="gender" value="female" />';
          echo '<input type = "radio name="gender" value="male" />';

          on page 2
          foreach ($_POST as $key=>$val)
          {
          echo '<input type = "hidden" name="'.htmlent ities($key).'"
          value="'.htmlen tities($val).'" />';
          }


          on page 3
          // do this any way u like. This will give an error in safe mode.
          $checked[$_POST['gender']]='checked="chec ked"';
          echo '<input type = "radio" name="gender" value="female"
          '.$checked['female'].'/>';
          echo '<input type = "radio" name="gender" value="male"
          '.$checked['male'].'/>';
          echo 'Your gender is'.$_POST['gender'];

          if it doen't work post the output of var_dump($_POST ); did you set your
          form right ?

          --
          Arjen
          http://www.hondenpage.com - Mijn site over honden

          Comment

          • Jerry Stuckle

            #6
            Re: Form in 2 steps - Preserving button radio

            elia wrote:
            Hello. Yes, already ask but no answers for this little problem.
            I've got a form and 3 steps or page for the same form. If we come back
            to the first page, the states of button radio are lost.
            >
            First page (form1.php)
            <?
            $gender=$_POST['gender'];
            if(isset($_POST['gender'])){
            $statusm="";
            $statusf="";
            if($_POST['gender']=="M"){$statusm ="checked"}
            else{$statusf=" checked"}
            ?>
            >
            <Form... action="form2.p hp">
            ...
            <input name="gender" type="radio" id="male" value="M"<?php echo
            $statusm
            ?>M
            <input name="gender" type="radio" id="female" value="F"<?php echo
            $statusf ?>>F
            ...
            </Form>
            >
            Second page (form2.php)
            <?
            $Gender=$_POST['gender'];
            ?>
            >
            <Form... action="form1.p hp">
            ...
            <input name="gender" type="hidden" id="gender" value="<? echo $gender ?
            >" />
            ...
            </Form>
            >
            But it doesn't work!!!
            >
            A solution could be with "session_start( )" and $_cookie but I don't
            know how to do it!
            >
            If anybody could write me all I need on the two pages with a little
            exemple?? (The same problem come with the checkox or choise with
            dynamic menu!) Thanks, pascal
            >
            Look at your source code. I think you'll find this comes out to

            <input name="gender" type="radio" id="male" value="M"CHECKE DM

            Note the lack of a space between "M" and CHECKED.

            --
            =============== ===
            Remove the "x" from my email address
            Jerry Stuckle
            JDS Computer Training Corp.
            jstucklex@attgl obal.net
            =============== ===

            Comment

            • elia

              #7
              Re: Form in 2 steps - Preserving button radio

              Extra!! All is ok, I had the same problem for the selected menu but is
              ok now with the same code, thanks a lot for all!! Pascal

              Comment

              Working...