close ad
 
Important WebAssist Announcement
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

Retain search sessions on many pages

Thread began 7/16/2013 5:41 pm by mrs | Last modified 7/19/2013 7:01 am by Jason Byrnes | 1530 views | 8 replies |

mrs

Retain search sessions on many pages

I am trying to get a search result to remain persistent across a number of pages. At the moment, I have a search results page that is now working, and I am purposefully returning a limited amount of results to keep the page relatively tidy because I am displaying results from numerous sections of my website. What I want is to show five events at most, and if there is more, then display a link to the events page which is using exactly the same recordset code as that of the search results page. When the user clicks that link, I want the search results to remain in place for that particular section.

How can I retain search results from the search results page and have them filter on the events page?

http://showmetransport.com is the site. If you search for london, five current events display, and a dummy link (eventually leading to the events page) will be shown with the amount of records found... currently 76 other results out of 770ish record entries. It's this link I need to know how to to pass the search results across to.

I have tried copying and pasting the relevant DA search code, including the required_file line of code into the events.php, but it didn't work.

Is what I am asking for possible with DA Search?

Thanks.

Sign in to reply to this post

mrs

In tandem with the above, I am also trying to do the following:

Because the search facility has a 'sticky' search effect until the search session is cleared down. I have tried:

<?php @session_start(); ?>
<?php
if (!session_id()) session_start();
if("" == "") {
$_SESSION["mrsSearch"] = "".((isset($_POST["searchbox"]))?$_POST["searchbox"]:"") ."";
}
?>

And then use <?php echo $_SESSION['mrsSearch']; ?> to show the user what they just searched for. This works OK, however, I was hoping to have a constant reminder so when the user moves away from the page, and then back, they are reminded that the search filter is still active, but the session is empty...

Any thoughts as to why?

Sign in to reply to this post

Jason ByrnesWebAssist

for the first question, send your pages so i can see how they are configured.

for the second question, the trigger you are using for setting the session is page load. This wikll set the session regardless of whether the searchbox form has been posted or not.

when you submit the search, it sets the session because the searchbox form element has a value, when you come back to the page, it sets the session to be blank because the searchbox form has not been submitted.

for the trigger, click the lightning bolt icon and select the searchbox form element same as the value so the session will only get set if the searchbox form element is posted.

Sign in to reply to this post

mrs

Got the second question sorted now, thank you.

The first I am still struggling on. I have tried copying and pasting the code from the working search results page, but I don't think that's working because the searchbox isn't populated, so I have tried the DataAssist Search from the server behaviours panel, but again, I think I am struggling with the trigger. I have set a session of mrsSearchActive on the search-results.php page which works, but is being wiped out when returning to the page, so I think the events.php is killing that session... I've tried using the trigger of $_SESSION['mrsSearchActive'] and on page load, but no joy!

As it now stands at the mo, events.php is a standard page without any search code in it.

Attached Files
events.php
search-results.php
Sign in to reply to this post

Jason ByrnesWebAssist

the first step is to set up the data assist search on the events page so it works exactly the same as the search on the search_results page.

you should be able to change the action of the search page to go to the events page and have the search for work,

when a search is done on the search_results page, the search is saved to a session named:
WADbSearch5_searchresults

there will also be a session that the search on the events page will save.

you can add code to the page to set the session on the events page to use the one that is set by the search results page.

Sign in to reply to this post

mrs

Nah... still didn't work, so I duped the search results page, deleted what I don't need and expanded on what I do need and all is now good as far as retaining the expected search result. However, my second posted question about retaining the entered search text is not working entirely again!

If I move from the search results page to another and click the back button, then I get an alert asking if I want to resubmit the search box. I click OK and the searched text show as I expect it to. If I click a text link on the page, the search results are still filtered as expected, but my searched text is now missing.

Obviously, on returning to the page in anyway apart from hitting the back button means the session I created has lost it's value for some reason, but I don't know why it keeps doing it.

The pages in question are attached.

Attached Files
search-events.php
search-results.php
Sign in to reply to this post

Jason ByrnesWebAssist

on setting the session:

<?php
// Set session for sticky searches
if (!session_id()) session_start();
if((((isset($_POST["searchbox"]))?$_POST["searchbox"]:"") != "")) {
$_SESSION["mrsSearchActive"] = "".((isset($_POST["searchbox"]))?$_POST["searchbox"]:"") ."";
}
else if((((isset($_POST["searchbox"]))?$_POST["searchbox"]:"") == "")) {
$_SESSION["mrsSearchActive"] = "0";
}
?>

your else statement is resetting the session if no form is submitted.

change that so it only sets the session if the form is submitted, and does nothing if it is not:
<?php
// Set session for sticky searches
if (!session_id()) session_start();
if((((isset($_POST["searchbox"]))?$_POST["searchbox"]:"") != "")) {
$_SESSION["mrsSearchActive"] = "".((isset($_POST["searchbox"]))?$_POST["searchbox"]:"") ."";
}
?>

Sign in to reply to this post

mrs

Yes, that is what is causing the issue, but upon removing that else if statement, I now get an 'Undefined index' error on show if regions that use the session to display. If the session has content from the search box in it, then all is well, but if the clear filter link is clicked - which takes me to a page to kill the search session and instantly redirects back - then I get this error:

Notice: Undefined index: mrsSearchActive in /Users/username/website/search-results.php on line 496

I added the else if to give it some value to prevent the error message... but I obviously broke it without realising what I had done!

I'm straining my brain to figure a way around it! I can't seem to keep the searched text by using the $_POST['searchbox'] alone as the page will not always be visited by the submission of the search!

How can I prevent the error message?

Sign in to reply to this post

Jason ByrnesWebAssist

that's what isset() is for:

php:
<?php echo(isset($_SESSION['mrsSearchActive'])?$_SESSION['mrsSearchActive']:""); ?>
Sign in to reply to this post

Build websites with a little help from your friends

Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.

Build websites from already-built web applications

These out-of-the-box solutions provide you proven, tested applications that can be up and running now.  Build a store, a gallery, or a web-based email solution.

Want your website pre-built and hosted?

Close Windowclose

Rate your experience or provide feedback on this page

Account or customer service questions?
Please user our contact form.

Need technical support?
Please visit support to ask a question

Content

rating

Layout

rating

Ease of use

rating

security code refresh image

We do not respond to comments submitted from this page directly, but we do read and analyze any feedback and will use it to help make your experience better in the future.

Close Windowclose

We were unable to retrieve the attached file

Close Windowclose

Attach and remove files

add attachmentAdd attachment
Close Windowclose

Enter the URL you would like to link to in your post

Close Windowclose

This is how you use right click RTF editing

Enable right click RTF editing option allows you to add html markup into your tutorial such as images, bulleted lists, files and more...

-- click to close --

Uploading file...