Search function on all website

I’m making a search bar you can access on the website, that is in the navbar. I can click this search bar to input a text and press enter to search for a word. So far, using a site.php controller, this seems to be working but this is not returning anything, because I need to redirect my search to localhost/search(?q=QUERY).

I’m using the basic controller (called site.php) and the recommended form.

<?php

return function ($site) {

    $query   = get('q');
    $results = $site->search($query, 'title|text');

    return [
        'query'   => $query,
        'results' => $results,
    ];
};


 <form>
     <input placeholder="Rechercher sur le site" type="search" aria-label="Search" name="q" value="<?= html($query) ?>">
     <input type="submit" value="Search">
 </form>

I’m not sure on how to redirect my user to the search page with the query, or if that is a recommended behaviour ? Thanks a lot.

This form has no action property, so it submits to the current page.

That’s true,
sor far I’ve tried this:

<form action="/search<?= html($query) ?>" method="GET">
    <input placeholder="Rechercher sur le site" type="search" aria-label="Search" name="q" value="<?= html($query) ?>">
     <input type="submit" value="Search">
</form>

But it doesn’t keep the query. I have to admit I am a little lost here… !

That doesn’t make sense, should be just search

Thanks, but it doesn’t search for the query, it only redirects me to /search. I have no clue on how to search for what was entered before the form submitted…
I was expecting this to send the query too…
/search?q=word

Have you removed the leading slash as well. To be on the safe side, I’d use the page url:

      <form action="<?= page('search')->url() ?>" method="GET">

Does the search page exist? What is the name of the txt file?

            <form action="<?= page('search')->url() ?>" method="GET">
                <input placeholder="Rechercher sur le site" type="search" aria-label="Search" name="q" value="<?= html($query) ?>">
                <input type="submit" value="Search">
            </form>

Is working,
Thanks a lot @texnixe.