Filtering autonav via dropdown menu

Permalink
Okay, I've done some searching on this, and I've not been able to find anything useful about it.

I am looking to be able to use a form, specifically something of a drop down menu, that can be used to set a filter type on multiple autonav blocks. The point is that I have a business directory, and the business pages attributes for location. I want to be able to view the directory (which is 4 different autonav blocks in one) that can be set to view only one location at a time, but if the option is not set or unset it does not filter at all.

I'd like to be able to set this as something like a session variable that can be referenced in multiple locations by all of the autonavs I am wanting to use.

You can see the directory here:http://mariposites.com/directory/...

But you can also go to any of the categories and view an autonav list of the ones in that category, then for the shops and services you can go to a business type (say hardware) and then see a page list of the ones listed there. I'm wanting to be able to let users select say "Location A", and then have all the browsing at that time be set to only viewing businesses of "Location A".

I am not sure exactly how to do this though. I've taken a look through the documentation for working with existing blocks (https://www.concrete5.org/documentation/developers/blocks/working-with-existing-blocks/) and searching and filtering files (https://www.concrete5.org/documentation/developers/files/searching-and/) but I'm not seeing a way to be able to set a universal setting that can be changed within a page. I'm fine if the page needs to reload to change the nav.

As a note, I think I could do this with javascript by putting in multiple blocks and setting the display to hide all but the one that should be viewed, but I'd rather do something different. I want something that loads ONLY the autonavs I set and using the option that the user sets.

Any help here?

 
12345j replied on at Permalink Reply
12345j
hmm. So you want to display a form, and based on the input of that form, grab a different block? What I'd do is to apply a different custom template to each menu, with a div around them, with a default value of display:none; Then, based on the value of what is selected, in the form (lookhttp://www.concrete5.org/documentation/how-tos/developers/basic-mvc... andhttp://www.concrete5.org/community/forums/usage/how-to-put-formand0... to find out how), change the value of one div to display:block;
Zudane replied on at Permalink Reply
as I explained, that is exactly what I DON'T want to do.

I want a drop down menu, that when an option is selected (using javascript onChange event if needed) will automatically refresh the page with the autonavs being limited to the selected attributes.

I want the blocks to change - not to hide the other blocks, but completely change them.



Maybe I should work this differently: How can I use a form (via php or html block) to set a session variable for a user, and then use an autonav block to call this variable as a filterByAttribute argument?
12345j replied on at Permalink Reply
12345j
then usehttp://www.c5tutorials.com/quick-tips/programatically-adding-a-bloc... and grab different settings based on the input.
Zudane replied on at Permalink Reply
The problem is that this still only loads it per page. I am wanting to have it go through to a session variable that can be called from multiple pages.

I am thinking though that I may need to set this to the database, but I want it to expire after x length of time... but I'm not certain how to do that.

Then again I'm not quite sure how to make a block like this, so many changes makes me think I may need to do this as a new block - although I may need be able to do just a custom template, right?

Perhaps a mix of html, javascript and mysql? I am thinking having the drop down menu call a javascript function from an onChange event that first runs php code to set the variable to the database along with a timestamp and then refreshes the page.

The lower amount of traffic should be okay for the database checks, although excessive browsing and needing this to be called from over a hundred pages could cause a problem.

Is there any way with C5 to write to the session variables? Since the user is logged in, there is a session, so shouldn't I just be able to have the javascript function set the session variable? The question is though how do I set that session variable to be used as an argument for the filterbyattribute?
jordanlev replied on at Permalink Reply
jordanlev
You can just write session variables as you would in any other php program:
$_SESSION['selected_location'] = $whatever;


Then you can read it like any other php program as well:
$whatever = isset($_SESSION['selected_location']) ? $_SESSION['selected_location'] : $default_value;


(note that all of the variable names in that code are just examples -- you would want to change those to something that is actually meaningful in your site)