Bug #20680 New

Search results template does work with template routes

Version: EE 2.9.2 Reporter: Derek Hogue

When using a template route (rather than a template path) as the “result_page” parameter of a search form, the result page returns “The action you have requested is invalid” error.

Looking at the search module code, the cached search query is fetched by looking at ee()->uri->query_string, which in the case of a template route is the entire series of segments, rather only the last segment, so the search module is looking up the cached query based on the first segment (i.e. “search”, or whatever your template route specifies), rather than the search ID hash.

This also affects {exp:search:keywords}.

  • Alas - my solution appears to fall down when the template route variables are named.

    Derek Hogue
    06th December, 2014 at 11:33am
  • This seems more reliable (though if you had another md5 string in your URL, it’s trouble):

    preg_match('/[a-f0-9]{32}/', ee()->uri->query_string, $matches);
    if(!empty($matches))
    {
     $search_id = $matches[0];
    }
    Derek Hogue
    06th December, 2014 at 11:45am

You must be signed in to comment on a bug report.

  • In mod.search.php, change all instances of:

    $search_id = substr(ee()->uri->query_string, 0, 32);

    And also:

    $qstring = explode('/', ee()->uri->query_string);
    $search_id = trim($qstring[0]);

    To:

    if(!empty(ee()->TMPL->template_route_vars))
    {
     $search_id = substr(end(ee()->TMPL->template_route_vars), 0, 32);
    }
    else
    {
     $search_id = substr(ee()->uri->query_string, 0, 32); 
    }

ExpressionEngine News

#eecms, #events, #releases