Orkun

Change filter selector without page refresh respectively get values through JS/jQuery to PHP to change Selectors?

Recommended Posts

I know that the Topic title is probably confusing(sry for that :)). Let me explain my Question:

I have two Filters(Main Filter & Detail Filter) like you can see below. When I click on a main filter it gets bold and will be added to the "Meine Auswahl(my selection)" container below the Filters. When I click on the "X" span inside the "My Selection" Container, the selected Filter gets resetted. Now, what I want to achieve is a ajax Filter which changes the php Selector for the for the $pages->find().

For Example:

When I come to that page, the selector for the main and detailfilter should look like this:

$branches = $pages->find("template=branch"); // Main Filters
<?php $genres = $pages->find("template=genre, select_sparte=''"); ?> //Detailfilters (Returns a NullPage so dont show the Detailfilters when none main filter is selected)

When I select for e.g Example Filter 1 it should change to this without a page refresh:

<?php $genres = $pages->find("template=genre, select_sparte.title='Example Filter 1'"); ?>

So that I get the Detail Filters of Example Filter 1 without a page refresh. Is this even possible? When yes how, can you guys show me a direction?

post-3125-0-83193300-1455626571_thumb.pn

post-3125-0-47611200-1455625934_thumb.pn

Share this post


Link to post
Share on other sites

You could write a PW page/template that handles nothing but the selectors and returns results as JSON. (written in PHP, with header("Content-type: application/json"); at the top)

On the page where this filter is used, you would include some JS that handles the user-selection and talks to the above-mentioned script via AJAX. json_encode + json_decode are your friend :)

  • Like 1

Share this post


Link to post
Share on other sites

You could write a PW page/template that handles nothing but the selectors and returns results as JSON. (written in PHP, with header("Content-type: application/json"); at the top)

On the page where this filter is used, you would include some JS that handles the user-selection and talks to the above-mentioned script via AJAX. json_encode + json_decode are your friend :)

Could you possibly make an example, or show one? That would be very helpful since I am not so advanced in AJAX/JSON.

Share this post


Link to post
Share on other sites

An easy way could also be using pjax, which does simply replace some container element of the dom instead of the whole page.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By anderson
      Hi,
      For the purpose of learning, as shown in this photo, I created a repeater field "we", then a template, then a page.
      But in /templates/testrepeater.php, I has some problem, the "foreach" part does not work as expected.
      <html> <body> <?php echo "<h1>$page->title</h1><br>"; ?> <? foreach($page->we as $member); ?> <img src="<?php echo $member->images->url; ?>" alt=""> <?php echo $member->wemember; ?><br> <? endforeach;?> </body> </html> Could anybody please help point out my error?
      Thanks in advance.

    • By pwFoo
      I played with the Selectors object and would like to use it for a special use case...
      That is a custom Selectors object with dummy data converted to an php array to see the structure (Selectors object is a WireArray with "fields" added)
      Array ( [0] => Array ( [0] => Array ( [field] => seg1 [value] => val1 [not] => [group] => [quote] => [forceMatch] => ) [1] => Array ( [field] => seg2 [value] => val2 [not] => [group] => [quote] => [forceMatch] => ) ) )  
      But instead of "seg1" the field name is "field" with value "seg1" (= my field name).
       
      So I can't search the Selectors WireArray (= custom WireArray with added Selectors objects) with PW "find('seg1=val1')", Is there a way to search with "find()" or build a simple wrapper to make the elements searchable / filterable with find()?
    • By Peter Knight
      <?php $Cats=$pages->find("parent=1086, id!=$page, sort=sort"); foreach($Cats as $Cat) { echo " I have a selector that pulls in 4 child pages of a parent and the order is set to reflect the order of the tree.
      My client has asked that instead of
      Cat 1 | Cat 2 | Cat 3 | Cat 4
      we instead display
      Cat 4 | Cat 1 | Cat 2 | Cat 3 
      However, I can't change the sort order in the tree.
      Can anyone guide me on the correct approach here?
      Thanks
       
    • By gregory
      Hi guys, I need help.
      how do I translate Next Page?
      <?php if($page->next->id) {echo "<div class='float-right'><a class='button' href='{$page->next->url}'> Next Page </a></div>";} ?> I usually use this:
      <?php $lang = $user->language->name; if($lang == 'default') {echo "Next Page";} else {echo "Pagina successiva";} ?> or
      <?php echo __("Next Page"); ?> Thanks
    • By nuel
      Hi there
      Basically I want to call code within a ProcessWire page that isn't used as a template. Example: www.mypwpage.com/myphpfile.php
      I have a working PW Website with a couple of pages like /artists, /releases, /videos etc. Now I need a page /download without any editable fields in the backend, just calling some PHP code (that was coded by another guy) containing a form that checks unique download-codes in a second database and starts the download of the desired file. The script is working fine right now as part of a static website, but since I built PW behind the site, this independent «Download Section» of the page doesn't work anymore.
      Right now I have the main file download.php as a page template on a newly created empty page called /download, so until now the form is working (wow). After sending the form containing the download-code, the file check_code.php in a subfolder /site/templates/download is called and that's where I get an error.
      Any help?