PDA

View Full Version : Adding search box to every page


Psycho1
04-17-2004, 05:05 PM
I'd like to add a simple search box to every page of my site...it would just have a search box to type in your query and a "go" button......how can I setup the simple search box to pass the query to the search.php file using the default options for results and operator?

vinyl-junkie
04-17-2004, 06:37 PM
The simplest way to do that is to have the search box code in an include file as part of either the header or footer for each page on your site. It's a good idea to have header and footer includes anyway, as it becomes much easier to change the look and feel of your site, should you ever decide to do that.

If you need a specific example of how to do that, I'd be glad to post some code for you. :)

Psycho1
04-17-2004, 06:41 PM
I'd love to see some example code!

vinyl-junkie
04-17-2004, 11:10 PM
OK, this was a little more complicated than I originally thought it would be, but here goes.

Find the following code in config.php:if ((isset($relative_script_path)) && ($relative_script_path != ".") && ($relative_script_path != "..")) {
exit();
} and modify it as follows:if ((isset($relative_script_path)) && ($relative_script_path != ".") && ($relative_script_path != "..") &&
($relative_script_path != "/your_complete_script_path")) {
exit();

Find the following code in config.php://template file and style
$template = "$relative_script_path/templates/template.php"; and delete it. Add that same bit of code into search.php just before this statement: phpdigSearch($id_connect, $query_string, $option, $refine,
$refine_url, $lim_start, $limite, $browse,
$site, $path, $relative_script_path, $template);

Create a file called searchbox.php and save it in the templates folder, with the following code:<table>
<tr>
<td>
<phpdig:form_title/>
</td>
</tr>
<tr>
<td>
<phpdig:form_field/>
<phpdig:form_button/>
<phpdig:form_select/>
</td>
</tr>
<tr>
<td>
<phpdig:form_radio/>
</td>
</tr>
</table>
In the body of your page(s) that you want the phpDig search box, insert the following code:$relative_script_path = 'full/path/to/phpdig';

include "$relative_script_path/includes/config.php";
include "$relative_script_path/admin/debug_functions.php";
include "$relative_script_path/libs/search_function.php";


// extract vars
extract(phpdigHttpVars(
array('query_string'=>'string',
'refine'=>'integer',
'refine_url'=>'string',
'site'=>'integer',
'limite'=>'integer',
'option'=>'string',
'lim_start'=>'integer',
'browse'=>'integer',
'path'=>'string'
)
));

//template file and style
$template = "$relative_script_path/templates/searchbox.php";

phpdigSearch($id_connect, $query_string, $option, $refine,
$refine_url, $lim_start, $limite, $browse,
$site, $path, $relative_script_path, $template);
Please test both the new pages and your original search page, to make sure I haven't left out any steps. I don't think I did, but you never know. ;)

Psycho1
04-18-2004, 11:10 AM
Thanks for that code vinyl-junkie! I can't make those modifications right now but I'll let you know how it turns out when I have the chance to.

vinyl-junkie
04-18-2004, 11:37 AM
You're welcome! :)

I just noticed an error in the code that I posted. In my previous post, I said to find the following code in config.php:if ((isset($relative_script_path)) && ($relative_script_path != ".") && ($relative_script_path != "..")) {
exit();
}
The correct replacement code should be:if ((isset($relative_script_path)) && ($relative_script_path != ".") && ($relative_script_path != "..") &&
($relative_script_path != "/your_complete_script_path")) {
exit();
}

Sorry about the mistake. You would get a parse error on the original code that I posted. :o

Psycho1
04-24-2004, 05:11 PM
I just tried it out and the only problem I'm encountering is the fact that clicking the Go button does nothing when you add the searchbox to other pages. The search.php still works for searching though. Also, in the searchbox.php file, are you sure it will work if I don't add the form_select and form_radio? I'd like the searchbox on other pages to have only the searchbox and the go button, but when you go to the search.php page you get all the options.

vinyl-junkie
04-25-2004, 09:04 AM
I must apologize for the problems you had with my code. I guess I didn't take my testing far enough with it. :o Sounds like I was making this more complicated than it needed to be anyway.

I think this is probably what you're looking for:
<center>
<p>Search My Website</p>
<form action='/path/to/search.php' method='get'>
<input type='hidden' name='template_demo' value='/path/to/templates/template.php'/>
<input type='hidden' name='site' value='0'/>
<input type='hidden' name='path' value=''/>
<input type='hidden' name='result_page' value='/path/to/search.php'/>
<input type='text' class='phpdiginputtext' size='15' maxlength='50' name='query_string' value=''/>
<input type='submit' class='phpdiginputsubmit' name='search' value='Go...'/>
<input type='hidden' name='limite' class='phpdigselect' value='10'>
</form>
This time I've thoroughly tested my code, so I know it works. ;)