Search error 404 when searching from pagination


I have a search input in the header, everything works except if I paginate in the results and perform a new search from there, it returns an error 404.

The url gets a double search/search http://sites:8888/kirby/search/search?q=test

:thinking: :thinking: :thinking:

Does your form have an action attribute? If in doubt, please post your form.

My form:

<form action="<?= page('search') ?>" autocomplete="off" class="search" method="get">
  <div class="form-group">
    <input id="search" name="q" onfocus="this.value=''" placeholder="Search..." type="search" value="<?= html($query) ?>">

That is pretty useless, should be <?= page('search')->url() ?>

1 Like

That made the trick! Thanks!

If we want to do it correctly, it should actually be

<?= ($p = page('search')) ? $p->url() : '' ?>

If you don’t mind, what does this line do compared to the other one? #curious

Also, a side note. If I use $results = $results->paginate(20); and there is pagination, <?= $results->count() ?> will return 20. How do I show the total number of results?

It makes sure that I have a (page) object, before I call the member function url() (that’s the stuff you should always do before you call non-static class methods).

2. question:

1 Like