[wp-hackers] Rewriting search URL

Sebastian Herp newsletter at scytheman.net
Sun Apr 24 10:08:54 GMT 2005


Your form needs to have an attribute "name" with the name of the form 
(e.g. "searchform"). Then the onclick-thing should be placed into the 
submitbutton tag.

 <form action="/" method="get" name="searchform">
  <fieldset>
   <input value="<?php echo wp_specialchars($s, 1); ?>" name="s" id="s" />
   <input type="submit" value="   !" id="searchbutton" 
onClick="document.searchform.method='post'; 
document.searchform.action='/search/' + document.searchform.s.value ;" />
  </fieldset>
 </form>

If the user has no javascript the form behaves like before. If he/she 
has it the method gets changed to "post" which can be a bad thing when 
the user tries to reload the search results ... but it works (see 
www.sebbi.de) ...


Peak Discharge wrote:

> Where exactly does the onclick bit go? At the moment I'm using the 
> following code to display a searchbox:
>  
>  <form action="/" method="get">
>   <fieldset>
>    <input value="<?php echo wp_specialchars($s, 1); ?>" name="s" id="s" />
>    <input type="submit" value="   !" id="searchbutton" />
>   </fieldset>
>  </form>
>  
> On 4/22/05, *Sebastian Herp* <newsletter at scytheman.net 
> <mailto:newsletter at scytheman.net>> wrote:
>
>     Add
>     onClick="document.searchform.method='post';
>     document.searchform.action='/search/' + document.searchform.s.value ;"
>
>     to your submit-button ... replace "searchform" with whatever name your
>     form has ...
>
>     Greetings,
>     Sebbi
>
>     Peak Discharge wrote:
>
>     > That changes my url into the form of
>     > http://www.unicorns.com/?s=string, which is a progress. The aim,
>     > however is to change all search urls to
>     > http://www.unicorns.com/search/string
>     <http://www.unicorns.com/search/string>
>     >
>     > On 4/22/05, *denis at semiologic.com <mailto:denis at semiologic.com>
>     <mailto:denis at semiologic.com <mailto:denis at semiologic.com>>*
>     > < denis at semiologic.com <mailto:denis at semiologic.com>
>     <mailto:denis at semiologic.com <mailto:denis at semiologic.com>>> wrote:
>     >
>     >     Quoting Peak Discharge <chmoka at gmail.com
>     <mailto:chmoka at gmail.com> <mailto: chmoka at gmail.com
>     <mailto:chmoka at gmail.com>>>:
>     >
>     >     > One of the things I love wp for is it's permalinks systems
>     that
>     >     utilizes
>     >     > mod_rewrite. I have tried tens of blog scripts in the past
>     but
>     >     wp's is the
>     >     > best one. One thing I have noticed, however, it does not
>     rewrite
>     >     the search
>     >     > URL. So instead of something neat such as '
>     >     > http://www.unicorns.com/search/unicorn'
>     <http://www.unicorns.com/search/unicorn%27>
>     >     <http://www.unicorns.com/search/unicorn%27>, I see
>     >     > '
>     http://www.unicorns.com/index.php?s=unicorn&searchbutton=Go%21
>     <http://www.unicorns.com/index.php?s=unicorn&searchbutton=Go%21>
>     >    
>     <http://www.unicorns.com/index.php?s=unicorn&searchbutton=Go%21
>     <http://www.unicorns.com/index.php?s=unicorn&searchbutton=Go%21>>
>     >
>     >     simply change the form's action's to "/" to solve this
>     >
>
>     _______________________________________________
>     wp-hackers mailing list
>     wp-hackers at lists.automattic.com
>     <mailto:wp-hackers at lists.automattic.com>
>     http://lists.automattic.com/mailman/listinfo/wp-hackers
>
>
>
>
> -- 
> best regards, chmoka
> mailto:chmoka at gmail.com <mailto:chmoka at gmail.com>
>
>------------------------------------------------------------------------
>
>_______________________________________________
>wp-hackers mailing list
>wp-hackers at lists.automattic.com
>http://lists.automattic.com/mailman/listinfo/wp-hackers
>  
>



More information about the wp-hackers mailing list