Hey guys,
i have some questions regarding an advanced search feature that i want to implement into my current project.
I set up the website to have a form with two input fields, one for the query one for the submit button inside the header. This “global search” should always search the whole website. To display the results i use the go('/url)'
function in conjunction with a query parameter like so: go('/search/?search=somerandomquery)'
.
Now we should be on the search page, which uses the search.php template and the search.php controller.
The template shows all $results as proposed by the docs or if the $results are empty it gives the visitor the opportunity to refine his search.
The advanced search shall work like this:
Additionally to the input field for a text search he may select checkboxes which refer to different templates of my website thus refining the pages that should be searched. Now the problem i am having is that i can’t pass the selected checkboxes into a new search query…
Template:
<fieldset class="small-12 medium-8 medium-centered columns">
<legend>Suche beschränken auf:</legend>
<input id="checkbox1" name="filter[]" value="checkbox1" type="checkbox"><label for="checkbox1">Produkte</label>
<input id="checkbox2" name="filter[]" value="checkbox2" type="checkbox"><label for="checkbox2">Lösungen</label>
(...)
<input type="search" name="q" value="<?php if (get('search') != ''){echo get('search');} else {echo esc($query);} ?>" placeholder="Suche">
<input type="submit" class="button expanded" value="Search">
Logic:
<?php
$query = get('search');
$filter = get('filter');
if ($query != '' && $filter != '') {
$params = implode(",",$filter);
go('suche/filter:'.$params.'/?search='.$query);
}
The first problem i encounter is that my url gets reformatted in a way that i don’t understand. After submitting the query with selected checkboxes and a string it looks like this:
http://url.com/suche/q=whatisearched&filter%5B%5D=checkbox1&filter%5B%5D=checkbox2#
… how can i route the query correctly and use it to find the right set of pages?
Maybe i should use routing instead of hacking urls with parameters? Any help is highly appreciated!
Thanks
Ps: optionally i want it to work to run the solution on a multi language setup later on…