Advanced Search

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…


     <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">


    $query = get('search');
    $filter = get('filter');
    if ($query != '' && $filter != '') {
        $params = implode(",",$filter);

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: … 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!


Ps: optionally i want it to work to run the solution on a multi language setup later on… :slightly_smiling:

That’s really strange and I don’t understand the generated URL structure either. Could you please replace the go( with a var_dump(?

Hey lukas,

thanks for the fast reply, sry it took me a while to answer and now it is already late xD. Anyway:

i removed the logic from the controller and temporarily put it in the template…

<?php echo implode(",",$filter); ?>

results in:
valueofcheckbox1, valueofcheckbox2
so i guess that > get(‘namecheckboxfield’) works and i should be able to get the info from the checkboxes in the controller in the same way.

The dump for:

looks like this:
string(22) "suche/filter:/?search="

But the url still looks like this after submitting:

… i don’t get where the “q” comes from and why the filters are being appended though… :slightly_smiling:
Thanks, good night, and until tomorrow :smiley:

Submitting the form is a whole different story and the resulting URL looks good to me. It looks like your go rule never applies.