Problem resetting sessions with only one button click

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

    Problem resetting sessions with only one button click

    Hello
    I am struggling for a solution to clear some fields on my webpage that takes
    their values from some sessions
    My solution below works when the button is clicked twice. I sort of know why
    I have to click it twice to do the job (the first submit resets the sessions
    but this it too late to change the field values, which requires another
    submit to pick up the new session values). Problem is I cant think how to
    accomplish the resetting of the fields to nothing with one click

    Code so far(below)
    *************** *************** ****
    <form name="form1" method="post" action="<?php echo $_SERVER['PHP_SELF'];
    ?>">
    <input name="Submit" type="submit" value=" Clear ">

    <?php
    if(isset($_POST['Submit'])){
    $_SESSION['savedcomm']='';
    $_SESSION['pupilfield']='';
    $_SESSION['gender']='';
    }
    ?>

    </form>
    *************** *************

    Help greatly appreciated
    Ian


  • Tommy Gildseth

    #2
    Re: Problem resetting sessions with only one button click

    Ian Davies wrote:[color=blue]
    > Hello
    > I am struggling for a solution to clear some fields on my webpage that takes
    > their values from some sessions
    > My solution below works when the button is clicked twice. I sort of know why
    > I have to click it twice to do the job (the first submit resets the sessions
    > but this it too late to change the field values, which requires another
    > submit to pick up the new session values). Problem is I cant think how to
    > accomplish the resetting of the fields to nothing with one click
    >
    > Code so far(below)
    > *************** *************** ****
    > <form name="form1" method="post" action="<?php echo $_SERVER['PHP_SELF'];
    > ?>">
    > <input name="Submit" type="submit" value=" Clear ">
    >
    > <?php
    > if(isset($_POST['Submit'])){
    > $_SESSION['savedcomm']='';
    > $_SESSION['pupilfield']='';
    > $_SESSION['gender']='';
    > }
    > ?>
    >
    > </form>
    > *************** *************
    >
    > Help greatly appreciated
    > Ian
    >
    >[/color]

    Simply rearange the order of the form, and the resetting of the session
    variables, so that the resetting of session variables comes before the
    form in the code?

    --
    Tommy Gildseth

    Comment

    • Ian Davies

      #3
      Re: Problem resetting sessions with only one button click

      thanks for your reply tommy

      unfortunately your suggestion doesnt work (also requiring two click)
      I think because of the following line

      if(isset($_POST['Submit'])){

      i suspect the problem with your solution is that $_POST['Submit'] isnt set
      until it is clicked (i think).
      i need the isset function to eliminate the problem of the sessions being
      changed during other events that occur on this page.

      Ian

      "Tommy Gildseth" <gildseth@start .no> wrote in message
      news:129j9l5m4j ecr91@corp.supe rnews.com...[color=blue]
      > Ian Davies wrote:[color=green]
      > > Hello
      > > I am struggling for a solution to clear some fields on my webpage that[/color][/color]
      takes[color=blue][color=green]
      > > their values from some sessions
      > > My solution below works when the button is clicked twice. I sort of know[/color][/color]
      why[color=blue][color=green]
      > > I have to click it twice to do the job (the first submit resets the[/color][/color]
      sessions[color=blue][color=green]
      > > but this it too late to change the field values, which requires another
      > > submit to pick up the new session values). Problem is I cant think how[/color][/color]
      to[color=blue][color=green]
      > > accomplish the resetting of the fields to nothing with one click
      > >
      > > Code so far(below)
      > > *************** *************** ****
      > > <form name="form1" method="post" action="<?php echo[/color][/color]
      $_SERVER['PHP_SELF'];[color=blue][color=green]
      > > ?>">
      > > <input name="Submit" type="submit" value=" Clear ">
      > >
      > > <?php
      > > if(isset($_POST['Submit'])){
      > > $_SESSION['savedcomm']='';
      > > $_SESSION['pupilfield']='';
      > > $_SESSION['gender']='';
      > > }
      > > ?>
      > >
      > > </form>
      > > *************** *************
      > >
      > > Help greatly appreciated
      > > Ian
      > >
      > >[/color]
      >
      > Simply rearange the order of the form, and the resetting of the session
      > variables, so that the resetting of session variables comes before the
      > form in the code?
      >
      > --
      > Tommy Gildseth
      > http://design.twobarks.com/[/color]


      Comment

      • Mtregael

        #4
        Re: Problem resetting sessions with only one button click

        Ian Davies a écrit :[color=blue]
        > Hello
        > I am struggling for a solution to clear some fields on my webpage that takes
        > their values from some sessions
        > My solution below works when the button is clicked twice. I sort of know why
        > I have to click it twice to do the job (the first submit resets the sessions
        > but this it too late to change the field values, which requires another
        > submit to pick up the new session values). Problem is I cant think how to
        > accomplish the resetting of the fields to nothing with one click
        >
        > Code so far(below)
        > *************** *************** ****
        > <form name="form1" method="post" action="<?php echo $_SERVER['PHP_SELF'];
        > ?>">
        > <input name="Submit" type="submit" value=" Clear ">
        >
        > <?php
        > if(isset($_POST['Submit'])){
        > $_SESSION['savedcomm']='';
        > $_SESSION['pupilfield']='';
        > $_SESSION['gender']='';
        > }
        > ?>
        >
        > </form>
        > *************** *************
        >
        > Help greatly appreciated
        > Ian
        >
        > [/color]
        Hi,

        Here is ONE example (i think there are many others...) that work to
        'clear' some session variables:


        1st page:
        test1.php:

        <?php
        session_start() ;
        $_SESSION['param1']="Param1";
        $_SESSION['param2']="Param2";
        $_SESSION['param3']="Param3";

        ?>
        <html>
        <head>
        <title>Test 1</title>
        </head>
        <body>

        <a href=test2.php> Next...</a>
        </body>



        2nd page:
        test2.php:

        <?php
        session_start() ;
        ?>
        <html>
        <head>
        <title>Test 2</title>
        </head>
        <body>
        <?php
        $param1=$_SESSI ON['param1'];
        $param2=$_SESSI ON['param2'];
        $param3=$_SESSI ON['param3'];
        echo "Param1: ".$param1."<br> ";
        echo "Param2: ".$param2."<br> ";
        echo "Param3: ".$param3."<br> ";
        ?>
        <form>
        <input type=button name=reset value=reset
        onclick="javasc ript:window.ope n('popup.php'); ">
        </form>
        </body>


        3st page:
        popup.php:

        <?php
        session_start() ;
        $_SESSION['param2']='';
        ?>
        <html>
        <head>
        <title>Test fenetre popup</title>
        </head>
        <body onload="javascr ipt:opener.loca tion.reload();s elf.close();">

        </body>



        I explain:

        test1.php: set some sessions variables 'param1' to 'param3'
        The "Next..." link to test2.php

        test2.php: show the session variables. One button "Reset" that call
        popup.php page

        popup.php: Clear the value of session variable 'param2', reload parent
        and close itself.

        When test2.php reload, you can see that 'param2' value is empty (but is
        set !)

        This need to have javascript enabled. Popup blockers don't block this
        'popup' because it is called directly from a button.
        You should not have actions on test2.php becaus it is reloaded after
        clicking 'reset' button.

        I hope this can help you...

        Regards,
        MtreGAEL
        Just try...

        Comment

        • Ian Davies

          #5
          Re: Problem resetting sessions with only one button click

          Thank you for your response
          Your suggestion was what I was looking for
          Although I couldnt get it to work properly with the javascript I did manage
          to get it to work using

          <?php
          session_start() ;
          header("Cache-control: private, no-store, no-cache, must-revalidate"); // IE
          6 Fix.
          header("Cache-Control: post-check=0, pre-check=0", false);
          header("Pragma: no-cache");
          $_SESSION['savedcomm']='';
          $_SESSION['pupilfield']='';
          $_SESSION['gender']='';
          header("Locatio n: http://www.mysite.co.u k/folder/file.php");
          ?>

          instead of your page three

          thanks
          ian


          "Mtregael" <gael.r0001@num ericable.fr> wrote in message
          news:4499cc7a$0 $166$a3f2974a@n nrp1.numericabl e.fr...
          Ian Davies a écrit :[color=blue]
          > Hello
          > I am struggling for a solution to clear some fields on my webpage that[/color]
          takes[color=blue]
          > their values from some sessions
          > My solution below works when the button is clicked twice. I sort of know[/color]
          why[color=blue]
          > I have to click it twice to do the job (the first submit resets the[/color]
          sessions[color=blue]
          > but this it too late to change the field values, which requires another
          > submit to pick up the new session values). Problem is I cant think how to
          > accomplish the resetting of the fields to nothing with one click
          >
          > Code so far(below)
          > *************** *************** ****
          > <form name="form1" method="post" action="<?php echo $_SERVER['PHP_SELF'];
          > ?>">
          > <input name="Submit" type="submit" value=" Clear ">
          >
          > <?php
          > if(isset($_POST['Submit'])){
          > $_SESSION['savedcomm']='';
          > $_SESSION['pupilfield']='';
          > $_SESSION['gender']='';
          > }
          > ?>
          >
          > </form>
          > *************** *************
          >
          > Help greatly appreciated
          > Ian
          >
          >[/color]
          Hi,

          Here is ONE example (i think there are many others...) that work to
          'clear' some session variables:


          1st page:
          test1.php:

          <?php
          session_start() ;
          $_SESSION['param1']="Param1";
          $_SESSION['param2']="Param2";
          $_SESSION['param3']="Param3";

          ?>
          <html>
          <head>
          <title>Test 1</title>
          </head>
          <body>

          <a href=test2.php> Next...</a>
          </body>



          2nd page:
          test2.php:

          <?php
          session_start() ;
          ?>
          <html>
          <head>
          <title>Test 2</title>
          </head>
          <body>
          <?php
          $param1=$_SESSI ON['param1'];
          $param2=$_SESSI ON['param2'];
          $param3=$_SESSI ON['param3'];
          echo "Param1: ".$param1."<br> ";
          echo "Param2: ".$param2."<br> ";
          echo "Param3: ".$param3."<br> ";
          ?>
          <form>
          <input type=button name=reset value=reset
          onclick="javasc ript:window.ope n('popup.php'); ">
          </form>
          </body>


          3st page:
          popup.php:

          <?php
          session_start() ;
          $_SESSION['param2']='';
          ?>
          <html>
          <head>
          <title>Test fenetre popup</title>
          </head>
          <body onload="javascr ipt:opener.loca tion.reload();s elf.close();">

          </body>



          I explain:

          test1.php: set some sessions variables 'param1' to 'param3'
          The "Next..." link to test2.php

          test2.php: show the session variables. One button "Reset" that call
          popup.php page

          popup.php: Clear the value of session variable 'param2', reload parent
          and close itself.

          When test2.php reload, you can see that 'param2' value is empty (but is
          set !)

          This need to have javascript enabled. Popup blockers don't block this
          'popup' because it is called directly from a button.
          You should not have actions on test2.php becaus it is reloaded after
          clicking 'reset' button.

          I hope this can help you...

          Regards,
          MtreGAEL
          Just try...


          Comment

          Working...