By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,950 Members | 1,019 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,950 IT Pros & Developers. It's quick & easy.

Problem resetting sessions with only one button click

P: n/a
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
Jun 21 '06 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Ian Davies wrote:
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


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/
Jun 21 '06 #2

P: n/a
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" <gi******@start.no> wrote in message
news:12*************@corp.supernews.com...
Ian Davies wrote:
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


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/

Jun 21 '06 #3

P: n/a
Ian Davies a écrit :
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


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=$_SESSION['param1'];
$param2=$_SESSION['param2'];
$param3=$_SESSION['param3'];
echo "Param1: ".$param1."<br>";
echo "Param2: ".$param2."<br>";
echo "Param3: ".$param3."<br>";
?>
<form>
<input type=button name=reset value=reset
onclick="javascript:window.open('popup.php');">
</form>
</body>
3st page:
popup.php:

<?php
session_start();
$_SESSION['param2']='';
?>
<html>
<head>
<title>Test fenetre popup</title>
</head>
<body onload="javascript:opener.location.reload();self.c lose();">

</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...
Jun 21 '06 #4

P: n/a
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("Location: http://www.mysite.co.uk/folder/file.php");
?>

instead of your page three

thanks
ian
"Mtregael" <ga********@numericable.fr> wrote in message
news:44*********************@nnrp1.numericable.fr. ..
Ian Davies a écrit :
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

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=$_SESSION['param1'];
$param2=$_SESSION['param2'];
$param3=$_SESSION['param3'];
echo "Param1: ".$param1."<br>";
echo "Param2: ".$param2."<br>";
echo "Param3: ".$param3."<br>";
?>
<form>
<input type=button name=reset value=reset
onclick="javascript:window.open('popup.php');">
</form>
</body>
3st page:
popup.php:

<?php
session_start();
$_SESSION['param2']='';
?>
<html>
<head>
<title>Test fenetre popup</title>
</head>
<body onload="javascript:opener.location.reload();self.c lose();">

</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...
Jun 23 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.