Allow search without intercepting form submission in JS (#1)

This commit is contained in:
pontus.horn
2016-08-25 19:29:40 +02:00
parent e3440a7d1a
commit 36fd7e1da8
2 changed files with 9 additions and 2 deletions

View File

@@ -27,6 +27,12 @@ class PicoSearch extends AbstractPicoPlugin
*/
public function onRequestUrl(&$url)
{
// If form was submitted without being intercepted by JavaScript, redirect to the canonical search URL.
if (preg_match('/^(.+\/)?search$/', $url) && $_GET['q']) {
header('Location: ' . $this->getPico()->getBaseUrl() . $url . '/' . urlencode($_GET['q']));
exit;
}
if (preg_match('/^(.+\/)?search\/([^\/]+)(\/.+)?$/', $url, $matches)) {
$this->search_terms = urldecode($matches[2]);