I have looked at Storing Form Data as a Session Variable, but nobody said how to undo the session once the user leaves that form. For me, once the session is set it is constantly set (until logged out I presume). So Username field for example will always have “test” in it if I unsuccessfully OR successfully submit the form with “test” in it and then just go to some other links. Here’s what I’ve got:
$_SESSION['temp_username'] = $_POST['username'];
Just clear the session data when it is not needed. You can do an
unsetagainst your temporary variables.But for the same reason, I think it would be better to store the form one level deeper:
Then you can retrieve
usernameas$_SESSION['formdata']['username']orunset$_SESSION['formdata'].