Here, more or less, is a step by step process:
liveSearchReq.open("GET", "./livesearch.php?s=" + document.forms.searchform.s.value);</code></pre>
And change it to this:
<pre><code>liveSearchReq.open("GET", "./index.php/livesearch/" + document.forms.searchform.s.value+"/");
Now, put that file at the root of your EE site.
<?php
global $IN, $DB, $LOC;
if (!$IN->QSTR)
{
exit;
}
$search_phrase =& urldecode($IN->QSTR);
$query = $DB->query("SELECT distinct(a.entry_id), a.url_title, a.title, b.blog_url
FROM exp_weblog_titles a, exp_weblogs b
WHERE a.weblog_id = b.weblog_id
AND a.status != 'closed'
AND (a.expiration_date > '".$LOC->now."' OR a.expiration_date = '0')
AND a.title LIKE '%{$search_phrase}%'
ORDER BY rand() LIMIT 0,10");
if ($query->num_rows == 0)
{
exit('No Results');
}
foreach($query->result as $row)
{
echo '<a href="'.$row['blog_url'].$row['url_title'].'">'.$row['title'].'</a><br />';
}
?>
<h4>Blog LiveSearch:</h4>
<form onsubmit="return liveSearchSubmit()" name="searchform" method="get" action="/index.php"
>
<input type="text" id="livesearch" name="s" size="15" autocomplete="off" onkeypress="liveSearchStart()" />
</form>
<div id="LSResult" style="display: none;"><div id="LSShadow"></div></div>
Oh, and at the top of the page, you will have to include the javascript file:
<script type="text/javascript" src="livesearch.js"></script>
Paul,
I have this live at the moment even though it’s not working. I’m getting very strange results. Would you mind having a look? my site.
I’m sure it’ll quickly be evident what it’s doing wrong. I’ve followed the steps fastidiuously, although it’s possible I made a mistake - I think I’ve got it the way you wrote.
Thanks Paul! =)
Sleep, yes, I should get more of that myself.
It is odd. In the javascript, you are using: index.php/livesearch/?s=search_term_here, whereas I made it so it went to a template: index.php/weblog/livesearch/search_term_here/. So you should modify it to be like that if you want my example to work. However, I just tried to look at the livesearch template on your site and I get your frontpage. Are you sure you created this page and that it is accessible to all users (even guests)?
It does not need to be in weblog, but you have to make sure you have the correct link to the template (and template group) in the javascript.
This:
liveSearchReq.open(“GET”, “./index.php/includes/livesearch/” + document.forms.searchform.s.value+”/”);
Not this:
liveSearchReq.open(“GET”, “./index.php/livesearch/” + document.forms.searchform.s.value+”/”);
Yes, well, if someone was brilliant enough, they would write this up as a plugin so the results could be created using a tag. If you know the weblog’s id, then you can easily just add a.weblog_id != ‘7’ or something like that in the query.
autocomplete is not valid (yet), but Camino, IE, Firefox, and Safari all accept it just fine. Up to you to determine if validity is important enough to do away with it.
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.