Filter search results by checking the boxes.

I have a search page where a user can enter a search field, or they can use an alphabetical list to search for the record they are looking for. For example, they press “a,” and all entries starting with the letter “a” appear.

I would also like to have it so that there are several tags in each entry, and I would like to be able to filter the entries according to which the tags were selected - preferably with checkboxes.

For example, perhaps the tags will be colored, and the posts are boots. The checkboxes for blue, yellow, black, brown, and so on will be set. At first, all colors will be shown, but if the user clicks on brown, then all but brown shoes will disappear.

I am using CakePHP

+3
source share
2 answers
 // cakephp view
 echo $this->Form->checkbox("Model.color.0", array("value"=>"green"));

 // cakephp controller
 $filtered = $this->Model->find("all", array(
   "conditions"=> array(
     // ...
   ) + $this->data
 ));
 //or
 $this->paginate['conditions'] = array(
   //...
 ) + $this->data;
 $filtered=$this->paginate();
+1
source

jQuery UI Autocomplete Plugin is what you are looking for.

Here you can try the demo: http://docs.jquery.com/UI/Autocomplete#demo

In the demo, they used a static local parameter. But you can also use a remote URL that displays a specific list based on your search query. Look at the various options.

Try it and if you have any problems (I'm sure you will), ask again here.

0
source

All Articles