Jump to content

Getting Site Search Script To Work

Recommended Posts

I downloaded a nifty little search script (you can see it at http://www.christersvensson.com/easy/) for my site and installed it as directed.


The search pages themselves work fine, but I also wanted to add a search box to each page so visitors can search directly from the pages. To set this up, I added the following code:

<!-- Search area -->

<div id="search_area">


/* Easy Real Time Full Text Search © 2012 Christer Svensson

---------------------------------------------- Instructions -------------------------------------------------------------------------------------------

 If the name of this file not is easy.php then rename it to easy.php

 Upload it to the directory (folder) on your homepage server that you want to search through.

 The PHP-script in this file performs a real time full text search of every htm, html, asp,
 and php file in the directory (folder) and all subdirectories (subfolders). The search is
 not case sensitive.

 The text displayed in the browser window is searched. For that reason, in the html code, all
 text in tags are omitted and also text between the tag and the end tag for head, script, noscript
 and iframe.

 You may translate the text (string values) in this file to your native language without the
 author's permission. If you do so, please send a copy to postbox@christersvensson.com and it
 will be published on the homepage of this script.

 You may also use another CSS style and you may include the script as a natural part at pages at
 your site.


// You may translate the string values here under to your native languages. 

$buttonvalue = "Search";
$search_at = "A search for";
$search_result = "returned these results";
$pages = "Number of pages with hits";
$to_small = "At least two characters are required";
$recursive = true;  // Change to false if no searching should be done in subdirectories.

//---------------------------- Do not change anything below this line -------------------------------------------------------------------------------

$html = <<<HTML
<form name="form" method="get" action="http://www.moralintelligence.net/easy.php">
<legend>Search Moralintelligence.net</legend>
<input type="text" value="Out of order. Click button. -->" name="search" size="30">
<a href="http://www.moralintelligence.net/easy.php"><input type="button" value="$buttonvalue" 
 onclick='window.location.assign(document.URL.substring(0,document.URL.indexOf("?")) + "?search=" + document.form.search.value.replace(/ /g,"%20"))'></a><br>
<!-- Please do not remove or change this link to the application's site. Others might like it too. -->
<small>Powered by <a href="http://www.christersvensson.com/easy/">Easy Real Time Full Text Search</a></small><br>

echo $html;



<!-- End search area -->

What I *want* this box to do is get the search query from the text entered by the user and then open a search page with the results (ideally in a different tab).


Here's what it *does* do, as tested in four modern browsers, using Windows 7:


1) Internet Explorer 11: No matter what text user enters, clicking "Search" causes the browser to reload the page with the search term added to the URL in the address bar. Nothing else happens.


2) Firefox 38: On first click, does as IE does. On second click, opens search page, but text area is blank, so user must re-enter search query.


3) Safari 5.1.7: Opens search page on first click, but user must re-enter search query.


4) Chrome 43: Does exactly as Safari does.




I *think* I'm not very far away from my intended result, but something seems to be missing or improperly configured, and I don't know enough about PHP to see what it is.


Please point me in the right direction.

Link to post
Share on other sites

Question withdrawn.


I finally figured out what was wrong: My input type for the "Search" button was "button" and needed to be "submit." :lol:


But ... if you want to help me improve my search pages, I would also like to ask any if two refinements can be added:


1) Pagination of results pages where there are many results. By default, the script renders one long, continuous page, and I'd rather split it into pages containing, say, 50 results each.


2) At the bottom of each search page, the script displays the number of pages with results.


I'd like to echo this at the top of the page: "A search for <search query> returned <n> results:" where <n> equals the number of pages with results on them. But since <n> is defined by the script as "$counter", and its value is determined by counting the result pages as the script finds and displays them, how would I modify the script to insert the value from "$counter" above the results?


As before, this seems as though it should be so simple.... :unsure:

Link to post
Share on other sites

Hmm. Three out of four.


The search bar now works correctly in Firefox, Chrome and IE -- but not in Safari. :blink:

Link to post
Share on other sites

I want to thank you for providing me with a venue to come in and talk to myself in front of a number of indifferent strangers.


Lord knows there's nowhere else I could go to do that. :clapping:

Link to post
Share on other sites

If possible, I'd like to have my last reply deleted.


I know, of course, that the fault is entirely mine, for posting a vague question that no one could answer. I will try to make future questions clearer.

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...