Welcome Guest, Not a member yet? Register   Sign In
Help storing and calling a cookie correctly
#1

[eluser]Chad Crowell[/eluser]
OK I am having users perform a search, the results of which are shown on the resulting view file, and then the search form is shown again on the search results view alongside the search results.

I want to populate the search form with the terms they just searched for, and what i did is, in the controller that grabs the search results, I placed the search terms in a cookie, then I grab that value when the view is shown and show it in the form field.

This is all working fine, but its one step behind. Let me exampleate:

I search for verizon
I see a new page with search results for verizon
On that same page, in the "search again" form field, I see nothing
I search for bellsouth
I see a new page with search results for bellsouth
On that same page, in the "search again" form field, I see "verizon"

So it appears that in the controller, even though I delete and then reset the cookie before calling the search results view, which would seem to me is the right way to do it, the cookie is still containing the previous value.

Any ideas?
#2

[eluser]erik.brannstrom[/eluser]
Why do you use cookies to store the value? I assume the search is performed using a standard form? If so, the value of your search is right in the $_POST variable. Just add something like
Code:
<input type="text" name="query" value="<?= isset($_POST['query']) ? $_POST['query'] : '' ?>" />
Wouldn't this work out?
#3

[eluser]Chad Crowell[/eluser]
Holy crap. Sometimes i'm really not an idiot. I swear. Thanks Erik




Theme © iAndrew 2016 - Forum software by © MyBB