PhpDig.net

Go Back   PhpDig.net > PhpDig Forums > How-to Forum

Reply
 
Thread Tools
Old 04-17-2004, 05:05 PM   #1
Psycho1
Green Mole
 
Join Date: Apr 2004
Posts: 9
Adding search box to every page

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?
Psycho1 is offline   Reply With Quote
Old 04-17-2004, 06:37 PM   #2
vinyl-junkie
Purple Mole
 
Join Date: Jan 2004
Posts: 694
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.
vinyl-junkie is offline   Reply With Quote
Old 04-17-2004, 06:41 PM   #3
Psycho1
Green Mole
 
Join Date: Apr 2004
Posts: 9
I'd love to see some example code!
Psycho1 is offline   Reply With Quote
Old 04-17-2004, 11:10 PM   #4
vinyl-junkie
Purple Mole
 
Join Date: Jan 2004
Posts: 694
OK, this was a little more complicated than I originally thought it would be, but here goes.

Find the following code in config.php:
PHP Code:
if ((isset($relative_script_path)) && ($relative_script_path != ".") && ($relative_script_path != "..")) {
  exit();

and modify it as follows:
PHP Code:
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:
PHP Code:
//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:
PHP Code:
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:
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:
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.

Last edited by vinyl-junkie; 04-17-2004 at 11:12 PM.
vinyl-junkie is offline   Reply With Quote
Old 04-18-2004, 11:10 AM   #5
Psycho1
Green Mole
 
Join Date: Apr 2004
Posts: 9
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.
Psycho1 is offline   Reply With Quote
Old 04-18-2004, 11:37 AM   #6
vinyl-junkie
Purple Mole
 
Join Date: Jan 2004
Posts: 694
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:
PHP Code:
if ((isset($relative_script_path)) && ($relative_script_path != ".") && ($relative_script_path != "..")) { 
  exit(); 

The correct replacement code should be:
PHP Code:
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.
vinyl-junkie is offline   Reply With Quote
Old 04-24-2004, 05:11 PM   #7
Psycho1
Green Mole
 
Join Date: Apr 2004
Posts: 9
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.
Psycho1 is offline   Reply With Quote
Old 04-25-2004, 09:04 AM   #8
vinyl-junkie
Purple Mole
 
Join Date: Jan 2004
Posts: 694
I must apologize for the problems you had with my code. I guess I didn't take my testing far enough with it. Sounds like I was making this more complicated than it needed to be anyway.

I think this is probably what you're looking for:
PHP Code:
<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.
vinyl-junkie is offline   Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Search box on every page? chrisdgreen How-to Forum 3 07-29-2005 10:27 AM
Blank page after adding code mods Brewer External Binaries 1 07-06-2005 01:34 PM
Adding a thumbnail to each page...help? huge_nerd How-to Forum 1 11-16-2004 10:54 AM
Adding search box to every page (cont'd) rogerh How-to Forum 1 10-11-2004 12:08 PM
Search box on html page rafarspd How-to Forum 4 12-04-2003 07:37 AM


All times are GMT -8. The time now is 03:54 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright © 2001 - 2005, ThinkDing LLC. All Rights Reserved.