View Full Version : Include Search on Another Page
zivester
06-10-2008, 02:28 PM
Is there a way for me to include my forum search in another page? I've looked through the code and there are hidden attributes that have random ID's, so it makes me kind of weary.
Is it possible to add forum search, as well as Member search to another page of my website? If so have you done it and how can it be done?
Lynne
06-10-2008, 02:52 PM
I think if you just include globals.php you will be able to include it. I have search included on a page I wrote and it works fine (you do need to make sure to include all the hidden inputs in the form).
zivester
06-10-2008, 03:37 PM
I included global.php, and hidden input elements of the form... I get the following error on search:
Your submission could not be processed because a security token was missing or mismatched.
Actually, if I include global.php from the forums, my page doesn't load... (btw I'm modding a photopost page to include the forum search).
[EDIT] Oh, I don't know if this matters... but I'm manually copying the fields from the search page to my other page to be able to format it the way I want.
Lynne
06-10-2008, 05:01 PM
You should copy the code for the form from the default vbulletin template because it will include the security token in it.
Did you use the 'template' in the article for How to create your own vBulletin-powered page! (uses vB templates) (https://vborg.vbsupport.ru/showthread.php?t=62164) to start your new page? You might want to read that article. I think you need to include a new line about the security token in the php page. Take a look in that article and see if it's mentioned.
edit: This article tells you what to put at the top of your page to deal with the security token - Implementing CSRF Protection in modifications (https://vborg.vbsupport.ru/showthread.php?t=177013)
zivester
06-10-2008, 06:27 PM
Thanks for the links Lynne... but my php is dieing...
Here is the top of my php file, it crashes on the require:
error_reporting(E_ALL & ~E_NOTICE);
define('NO_REGISTER_GLOBALS', 1);
define( 'THIS_SCRIPT', "search" );
define('CSRF_PROTECTION', true);
//require_once( "{$Globals['PP_PATH']}/forum/global.php" );
Lynne
06-10-2008, 07:19 PM
Thanks for the links Lynne... but my php is dieing...
Here is the top of my php file, it crashes on the require:
error_reporting(E_ALL & ~E_NOTICE);
define('NO_REGISTER_GLOBALS', 1);
define( 'THIS_SCRIPT', "search" );
define('CSRF_PROTECTION', true);
//require_once( "{$Globals['PP_PATH']}/forum/global.php" );
Have you tried changing the require_once to include the actual path and see if that works? Is this page you are adding in the forum directory? If so, just include it like this:
require_once('./global.php');
If it's in a different directory, then do a chdir first, like this:
chdir('/path/to/forum/');
require('./global.php');
zivester
06-10-2008, 07:29 PM
Ya I learned that issue.. so I'm past that part... right now I'm getting the search to show up, but the values for half of the options are blank!?
chdir('/my/dir/mysite/forum/');
require('./global.php');
// ################################################## #####################
// ######################## START MAIN SCRIPT ############################
// ################################################## #####################
$navbits = array();
$navbits[$parent] = 'Test Page';
$navbits = construct_navbits($navbits);
eval('$navbar = "' . fetch_template('navbar') . '";');
eval('print_output("' . fetch_template('search_forums') . '");');
EDIT: in IE, there are numerous Javascript errors when I include it as stated above... I think these are causing the problem. Another note, I'm not running this from within the vBulletin portion of my server, but one directory down.
--------------- Added 1213132230 at 1213132230 ---------------
EDIT EDIT:
memberlist_search template included doesn't work either... I must be missing an include or the javascript is screwing it up?
--------------- Added 1213156743 at 1213156743 ---------------
Here's a link to the test page to see what I mean:
http://www.streetstyle.com/search2.php
Any help appreciated :(
Dismounted
06-11-2008, 07:12 AM
Put this at the top of your headinclude template.
<base href="http://www.streetstyle.com/forum/" />
zivester
06-11-2008, 01:03 PM
That didn't change anything... :-/
I've linked it back to the search_forums template, in order to work out the kinks... Here is the whole file for search2.php:
<?php
// ####################### SET PHP ENVIRONMENT ###########################
error_reporting(E_ALL & ~E_NOTICE);
// #################### DEFINE IMPORTANT CONSTANTS #######################
define('NO_REGISTER_GLOBALS', 1);
define('THIS_SCRIPT', 'search2'); // change this depending on your filename
// ################### PRE-CACHE TEMPLATES AND DATA ######################
// get special phrase groups
$phrasegroups = array(
);
// get special data templates from the datastore
$specialtemplates = array(
);
// pre-cache templates used by all actions
$globaltemplates = array(
'SEARCH2',
);
// pre-cache templates used by specific actions
$actiontemplates = array(
);
// ######################### REQUIRE BACK-END ############################
chdir('/my/stuffhtml/blah/forum/');
require('./global.php');
// ################################################## #####################
// ######################## START MAIN SCRIPT ############################
// ################################################## #####################
$navbits = array();
$navbits[$parent] = 'Test Page';
$navbits = construct_navbits($navbits);
eval('$navbar = "' . fetch_template('navbar') .'";');
eval('print_output("' . fetch_template('search_forums') . '");');
?>
Lynne
06-11-2008, 01:58 PM
So, with the script you just posted, what sort of errors or results are you getting?
zivester
06-11-2008, 02:35 PM
Check it out in the link I posted:
http://www.streetstyle.com/search2.php
Half of the options on the search page aren't loaded/are missing... its very weird :-/
Lynne
06-11-2008, 03:03 PM
Well, if that is all you have in your page, then you will need to add quite a bit. You need the code to populate all the drop-downs and the forum list, etc. You may even need to include the search phrasegroup. I'd start by taking a look at the search.php page and copying some of the code from there since you are doing another search page.
zivester
06-11-2008, 04:46 PM
Just breaking it down to something as simple as the following line:
<select name="titleonly">
<option value="0" $titleonlyselected[0]>$vbphrase[search_entire_posts]</option>
<option value="1" $titleonlyselected[1]>$vbphrase[search_titles_only]</option>
$vbphrase[search_titles_only] prints perfectly fine, while $vbphrase[search_entire_posts] does not...
There is no reference to either of these in search.php.... has anyone successfully created their own search page using the vBulletin templates?
--------------- Added 1213219314 at 1213219314 ---------------
Ok.. I got the forms to showup correctly.. but now when I make searches, I get a "search id is not valid or has expired"
Where do I go from here?
Lynne
06-11-2008, 08:36 PM
search_titles_only is a Global phrase. search_entire_posts is a Searching phrase. So, you need to include the 'search' phrasegroup at the top of your script.
As for the search id, is it getting inserted into the database when the search is first performed?
zivester
06-11-2008, 09:13 PM
$searchforumbits is the only part of the page that isn't getting filled out... I've included the necessary files to get the rest to fill out, but can't figure our where those are set..
hmmm
I'm thinking its some linking issue? note: I have changed the base URL at the top of the page to /forum/
Lynne
06-11-2008, 09:17 PM
If you look at the vb search.php page, they define $searchforumbits around line 2065. Have you included the code for that in your custom page? (It needs the line above that which calls a function so you need to include the page that the function is in also.)
zivester
06-11-2008, 09:17 PM
Oh Snap... even my regular search isn't working... what did I do ?
EDIT:
and Memberlist Search does work...
--------------- Added 1213223628 at 1213223628 ---------------
I think it only doesn't work, when it is actually returning a result... cause if i search for some random word, it'll return saying it didn't find it.. but if i search for a word that i know is there, like "celtics" it throws the error.
vBulletin® v3.8.12 by vBS, Copyright ©2000-2025, vBulletin Solutions Inc.