You are here: Re: Problem resetting sessions with only one button click « All PHP « IT news, forums, messages
Re: Problem resetting sessions with only one button click

Posted by Mtregael on 06/21/06 22:47

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.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...

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация