We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Simple Search - Change template route?

How Do I?

Andy @ Pillory Barn's avatar
Andy @ Pillory Barn
130 posts
8 years ago
Andy @ Pillory Barn's avatar Andy @ Pillory Barn

Hey guys,

Now I have simple search working properly, is it possible to create a template route to change how the template is loaded?

For example, say I have this as the results template -

blog/search-results

But i’d like to change the template route to something like -

usa/search/results/6ebf3adc2fb6770a95c0dfc83e513b10/

I’ve tried something like this -

/{searchcountry:regex[(zh|cn|usa)]}/search/results/{alpha_dash}/

But it just fails and says “The action you have requested is invalid.”

       
James Mathias's avatar
James Mathias
225 posts
8 years ago
James Mathias's avatar James Mathias

Hi,

Could you post your full simple search tag, so I can see in context what you are trying to do?

Thanks!

       
Andy @ Pillory Barn's avatar
Andy @ Pillory Barn
130 posts
8 years ago
Andy @ Pillory Barn's avatar Andy @ Pillory Barn

Hey James,

Sure, here you go:

{exp:search:simple_form 
    form_class="header-search" 
    where="any" 
    search_in="everywhere" 
    channel="static|homepage|news_resources|case_studies" 
    result_page="{segment_1}/blog/search-results" 
    no_result_page="{segment_1}/blog/noresults"
    }
        <input type="text" name="keywords" id="keywords" value="" placeholder="Search...">
        <input type="submit" id="search-submit" name="submit" value="">
{/exp:search:simple_form}

So as an example of the way the site works, you can access the site via something like example.com/usa/search or example.com/zh/search or example.com/cn/search. We use the first segment to control what contact information is shown.

So I tried a route like this -

/{searchcountry:regex[(zh|cn|usa)]}/search/results/{alpha_dash}/

And while it kinda tries to load the route, it always throws the error

“The action you have requested is invalid.”

Andy

       
James Mathias's avatar
James Mathias
225 posts
8 years ago
James Mathias's avatar James Mathias

Hi,

If you change your result_page parameter to result_page='{segment_1}/search/results' it should work as you expect.

       
Andy @ Pillory Barn's avatar
Andy @ Pillory Barn
130 posts
8 years ago
Andy @ Pillory Barn's avatar Andy @ Pillory Barn

I’ve tried that, I still get the error -

The following errors were encountered

The action you have requested is invalid.
Return to Previous Page
       
James Mathias's avatar
James Mathias
225 posts
8 years ago
James Mathias's avatar James Mathias

Hi,

Hmmm. That should work.

Are you using a member account that has permission to use the search feature?

Are you searching for something that should return results?

Are you setting a route for the no_result_page parameter as well?

       
Andy @ Pillory Barn's avatar
Andy @ Pillory Barn
130 posts
8 years ago
Andy @ Pillory Barn's avatar Andy @ Pillory Barn

Yeah the search without using {segment_1} works completely fine, but when we’re trying to add this segment it always throws this error.

Yep searching for something that would return a result and yep a route is set for both

       
Andy @ Pillory Barn's avatar
Andy @ Pillory Barn
130 posts
8 years ago
Andy @ Pillory Barn's avatar Andy @ Pillory Barn

My url for the search is

example.com/usa/search/results/f182b25cab8bbde323d3f3f7ca21d1d8/

with the route

/{searchcountry:regex[(zh|cn|usa)]}/search/results/{alpha_dash}/
       
James Mathias's avatar
James Mathias
225 posts
8 years ago
James Mathias's avatar James Mathias

Hi,

I wonder if the {segment_1} isn’t being parsed in the form parameter?

I’ll run this by the team when they come in, and see if we can determine what’s happening. And I’ll try to replicate. What version of ExpressionEngine is this failing on?

       
Andy @ Pillory Barn's avatar
Andy @ Pillory Barn
130 posts
8 years ago
Andy @ Pillory Barn's avatar Andy @ Pillory Barn

Hey James,

It’s on 3.4.1. To give you an idea of the form block, here’s the HTML

I’ve replaced our live URL with example.com as I can’t post publicly, but feel free to email me - andy[at]pillorybarn.co.uk

<form class="header-search" method="post" action="http://www.example.com/" _lpchecked="1">
 <div class="hiddenFields">
  <input type="hidden" name="ACT" value="21">
  <input type="hidden" name="RES" value="">
  <input type="hidden" name="meta" value="KoT6RYQD5DBBXX3OGP+A0MqZgRAJ4R0VgqlYj7jXKdBT9I5RZbrGcdSnxv0R45YuPcUlI3k+Z2op54YjtseSJdSs2nY0RZGFVDFWUy1skSQaibj6PW0beThZrVlVLCcrwJdcPGwk9ueyHrFysAcDUYOCkL9w6OEnFaRcbTnQzj5YNDfcSP9gV+uWRW+ssC1+W+IL2JA6FYd7NczVbGLFc9+N9k7mT1iXhCs9jVFN75VOnXDVjZJm2Gvi8JDcxDwJ74UaiGd0/n8ER4V1nhhkOybHzmWRkI1mnlMyJGl5FYXtMcHKQzTjhdGVELkI30BqrV+5cIUHgVCpBOoBgY2RJSSfB+glZT6jTakY2fc7+7CqNp98+7iRQJqvvk1CqiRUZhnFA9nBj0aA+6DS5NllRH7dpvUv9mccAf5oGY/YPaDLTERHKsMmMHY+tcIuN25zoP0t6jiaV3JwAW2GSgRbnw==">
  <input type="hidden" name="site_id" value="1">
  <input type="hidden" name="csrf_token" value="ea0bbba7708a5d6cafbed1ca4f08f6c995ea85e6">
 </div>

    <input type="text" name="keywords" id="keywords" value="" placeholder="Search...">
    <input type="submit" id="search-submit" name="submit" value="">
</form>
       
James Mathias's avatar
James Mathias
225 posts
8 years ago
James Mathias's avatar James Mathias

Hi Andy,

Looks like this one is a bug, I’ve filed it as such here: https://support.ellislab.com/bugs/detail/22411 You can subscribe to that to be notified of potential fixes and patches.

       
Andy @ Pillory Barn's avatar
Andy @ Pillory Barn
130 posts
8 years ago
Andy @ Pillory Barn's avatar Andy @ Pillory Barn

Ah at least that means I’m not going insane! haha. Thanks for looking into this James, thought that it should work so was completely thrown when it wasn’t

Andy

       
James Mathias's avatar
James Mathias
225 posts
8 years ago
James Mathias's avatar James Mathias

No worries, I thought it should work too!

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.