ArizonaJohn Posted May 28, 2009 Share Posted May 28, 2009 Hello, I have the following HTML form at the top of a page called tsearch18.php. This page uses the variable "find" as a session variable. I would like the value of "find" to remain constant unless the user hits the submit button on the form below (or of course types a new value into the form and hits enter). So, I would like to trigger "unset($_SESSION['find']);" whenever the HTML form is used. But only then. How can I do this? I am having a hard time figuring out where to put "unset($_SESSION['find']);" I tried an if statement and it didn't work. Thanks in advance, John <div class="searchbox"> <form action="tsearch18.php" method="post"> <label>Enter Topic: <input type="text" name="find" size="55"/> <input type="hidden" name="searching" value="yes" /> <input type="submit" name="search" value="Search" /> </label> </form> </div> Link to comment https://forums.phpfreaks.com/topic/160065-refreshing-session-variable-with-an-html-form/ Share on other sites More sharing options...
paulman888888 Posted May 28, 2009 Share Posted May 28, 2009 add an if if(isset($_POST['submit'])){unset($_SOMeTHING)} Link to comment https://forums.phpfreaks.com/topic/160065-refreshing-session-variable-with-an-html-form/#findComment-844444 Share on other sites More sharing options...
waynew Posted May 28, 2009 Share Posted May 28, 2009 if(isset($_POST['find'])){ if(isset($_SESSION['find'])){ unset($_SESSION['find']); } } Link to comment https://forums.phpfreaks.com/topic/160065-refreshing-session-variable-with-an-html-form/#findComment-844536 Share on other sites More sharing options...
ArizonaJohn Posted May 28, 2009 Author Share Posted May 28, 2009 Hi Waynewex, That code does what I want... but I only want it to do that if the "Search" button is clicked. And then after the "Search" button is clicked, I want to re-set the session variable and keep it live. So far I can't get it to work. Link to comment https://forums.phpfreaks.com/topic/160065-refreshing-session-variable-with-an-html-form/#findComment-844568 Share on other sites More sharing options...
waynew Posted May 28, 2009 Share Posted May 28, 2009 if(isset($_POST['search'])){ if(isset($_SESSION['find'])){ unset($_SESSION['find']); } $_SESSION['find'] = $_POST['find']; } Link to comment https://forums.phpfreaks.com/topic/160065-refreshing-session-variable-with-an-html-form/#findComment-844580 Share on other sites More sharing options...
ArizonaJohn Posted May 28, 2009 Author Share Posted May 28, 2009 Hi Waynewex, Almost there... this is a little weird, but it works if the HTML form is used twice. So when I hit enter, the result is whatever had been entered into the search bar one attempt previously. Any ideas why it is doing that? Thanks Link to comment https://forums.phpfreaks.com/topic/160065-refreshing-session-variable-with-an-html-form/#findComment-844591 Share on other sites More sharing options...
waynew Posted May 28, 2009 Share Posted May 28, 2009 So you're only wanting it to be set once, and no more thereafter? Link to comment https://forums.phpfreaks.com/topic/160065-refreshing-session-variable-with-an-html-form/#findComment-844596 Share on other sites More sharing options...
ArizonaJohn Posted May 29, 2009 Author Share Posted May 29, 2009 No, I want the user to be able to reset without limit... every time something is entered into the HTML form. Link to comment https://forums.phpfreaks.com/topic/160065-refreshing-session-variable-with-an-html-form/#findComment-844602 Share on other sites More sharing options...
fullyscintilla Posted May 29, 2009 Share Posted May 29, 2009 why do you need it stored in a session variable at all then..? Link to comment https://forums.phpfreaks.com/topic/160065-refreshing-session-variable-with-an-html-form/#findComment-844606 Share on other sites More sharing options...
ArizonaJohn Posted May 29, 2009 Author Share Posted May 29, 2009 Later on, I use Ajax that refers to another page where I need the value of "find" to remain constant. Link to comment https://forums.phpfreaks.com/topic/160065-refreshing-session-variable-with-an-html-form/#findComment-844609 Share on other sites More sharing options...
fullyscintilla Posted May 29, 2009 Share Posted May 29, 2009 you could always create a secondary session variable to temp hold on to values and then reset that value each time a new value is submitted Link to comment https://forums.phpfreaks.com/topic/160065-refreshing-session-variable-with-an-html-form/#findComment-844612 Share on other sites More sharing options...
ArizonaJohn Posted May 29, 2009 Author Share Posted May 29, 2009 How would I do that? Link to comment https://forums.phpfreaks.com/topic/160065-refreshing-session-variable-with-an-html-form/#findComment-844614 Share on other sites More sharing options...
fullyscintilla Posted May 29, 2009 Share Posted May 29, 2009 if(isset($_POST['search']) { $Find = $_POST['find']; $_SESSION['find'] = $_POST['find']; } ? Hard to tell without knowing the rest of your code Link to comment https://forums.phpfreaks.com/topic/160065-refreshing-session-variable-with-an-html-form/#findComment-844615 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.