Go Back   vb.org Archive > vBulletin 4 Discussion > vB4 Programming Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 02-24-2012, 09:46 AM
deverill2010 deverill2010 is offline
 
Join Date: Jan 2011
Posts: 412
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Radio Buttons for search

I currently have a custom google search bar on my site which only searches sites that I have allowed in google when creating the search. The search results are also displayed within a page which looks like my website. This all works fantastically well but I would like to add to improve the search.

I want to add two radio buttons, one for WWW and one for my site, so when the radio button WWW is selected it does as abve searches the sites I have allowed in google and displays them within its page as it currently does.

When my sites radio button is selected it just does a quick search of MY SITE only and displays the results in a page looking like my site.

I have tried before to do this but haven't been able to master it, I would really appreciate any help as I really realy want this.

Here is my crrent search code in the navbar template -

Code:
		<div id="globalsearch" class="globalsearch">
<form action="http://www.midwiferyonline.co.uk/googlesearch.php" id="cse-search-box">
  <div>
    <input type="hidden" name="cx" value="partner-pub-XXXXXXXXXXXXXXXXXXXXXXXX" />
    <input type="hidden" name="cof" value="FORID:10" />
    <input type="hidden" name="ie" value="UTF-8" />
  <span class="textboxcontainer"><span>  <input type="text" name="q" size="20" /></span></span>
<span class="buttoncontainer"><span><input type="image" class="searchbutton" src="{vb:stylevar imgdir_button}/search<vb:if condition="$stylevar['textdirection'] == 'rtl'">_rtl</vb:if>.<vb:if condition="(is_browser('ie') AND !is_browser('ie', 7) AND !is_browser('ie', 8))">gif<vb:else />png</vb:if>" name="submit" onclick="document.getElementById('navbar_search').submit;" tabindex="100"/></span></span>
  </div>
</form>
And my google search.php

PHP Code:
<?php



// ####################### SET PHP ENVIRONMENT ###########################

error_reporting(E_ALL & ~E_NOTICE);



// #################### DEFINE IMPORTANT CONSTANTS #######################



define('THIS_SCRIPT''Googlesearch');

define('CSRF_PROTECTION'true);  

// 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('googlesearch',

);



// pre-cache templates used by specific actions

$actiontemplates = array();



// ######################### REQUIRE BACK-END ############################

// if your page is outside of your normal vb forums directory, you should change directories by uncommenting the next line

// chdir ('/path/to/your/forums');

require_once('./global.php');



// #######################################################################

// ######################## START MAIN SCRIPT ############################

// #######################################################################



$navbits construct_navbits(array('' => 'Google Search'));

$navbar render_navbar_template($navbits);



// ###### YOUR CUSTOM CODE GOES HERE #####

$pagetitle 'Google Search';



// ###### NOW YOUR TEMPLATE IS BEING RENDERED ######



$templater vB_Template::create('googlesearch');

$templater->register_page_templates();

$templater->register('navbar'$navbar);

$templater->register('pagetitle'$pagetitle);

print_output($templater->render());



?>
Any help please?
Attached Images
File Type: jpg search.jpg (23.9 KB, 0 views)
File Type: jpg current search.jpg (61.0 KB, 0 views)
Reply With Quote
  #2  
Old 02-26-2012, 03:41 PM
deverill2010 deverill2010 is offline
 
Join Date: Jan 2011
Posts: 412
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Anyone able to help me please as I'm stumped!
Reply With Quote
  #3  
Old 02-26-2012, 04:20 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

You might be able to do that with javascript. Add an onsubmit function to the form tag, and if the radio button is selected for your site, change the action of the form to search.php?do=process. You also need the search term to be in a variable called "query", so you could add a new hidden field named query and set it to the value of the q input field if you're going the site search page.
Reply With Quote
  #4  
Old 02-26-2012, 04:23 PM
deverill2010 deverill2010 is offline
 
Join Date: Jan 2011
Posts: 412
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Thank you for replying but that just went straight over my head lol. I've never wrote JavaScript before and as for the rest of it I have no idea. I thought it would be something easy that I was just too thick to see.

Reply With Quote
  #5  
Old 02-26-2012, 04:30 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

There may be some other way to do it - you can probably redirect to the search page from the php script. But to be honest I can't quite figure out how that script works because it seems that it doesn't do anything except display a template.
Reply With Quote
  #6  
Old 02-26-2012, 04:44 PM
deverill2010 deverill2010 is offline
 
Join Date: Jan 2011
Posts: 412
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Lol oops that's because it does..

Here's the template -

Code:
{vb:stylevar htmldoctype}
<html xmlns="http://www.w3.org/1999/xhtml" dir="{vb:stylevar textdirection}" lang="{vb:stylevar languagecode}" id="vbulletin_html">
  <head>
    <title>{vb:raw vboptions.bbtitle} - {vb:raw pagetitle}</title>
    {vb:raw headinclude}
    {vb:raw headinclude_bottom}
  </head>
  <body>
    
    {vb:raw header}
    
    {vb:raw navbar}
    
    <div id="pagetitle">
      <h1>{vb:raw pagetitle}</h1>
    </div>
    
    <h2 class="blockhead">Your are searching using Google!</h2>
    <div class="blockbody">
      <div class="blockrow">
<div id="cse-search-results"></div>
<script type="text/javascript">
  var googleSearchIframeName = "cse-search-results";
  var googleSearchFormName = "cse-search-box";
  var googleSearchFrameWidth = 800;
  var googleSearchDomain = "www.google.co.uk";
  var googleSearchPath = "/cse";
</script>
<script type="text/javascript" src="http://www.google.com/afsonline/show_afs_search.js"></script>
      </div>
    </div>
    
    {vb:raw footer}
  </body>
</html>
So the bit in the navbar template is the google search box with my Adsense code.

When something is searched for The php page renders the template to display the results from google into (my google search template, the code in this post).

It's so the results look a part of my site. Does that make sense?
Reply With Quote
  #7  
Old 02-26-2012, 05:09 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

You could try putting something like this near the beginning of your php script (maybe just under require_once('./global.php')):

PHP Code:
if ($_REQUEST['radio_button'] == ???)
{
    
$vbulletin->url 'search.php?do=process&query=' $_REQUEST['q'];
    
print_standard_redirect(''false);


the 'if' condition needs to be changed, I couldn't figure it out because you provided a picture of the radio buttons but not the code (or maybe you only made a picture?)

ETA: the $_REQUEST['q'] probably needs to be encoded for a url - I'll have to look that up.
Reply With Quote
  #8  
Old 02-26-2012, 05:12 PM
deverill2010 deverill2010 is offline
 
Join Date: Jan 2011
Posts: 412
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Thanks, Yeah I only made a picture lol, I haven't done the code for the radio buttons as I don't now how to incorporate that into what I've already got.

I find it a lot harder editing/adding to something that already exists than writing something of my own from scratch.
Reply With Quote
  #9  
Old 02-26-2012, 05:21 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Well, I only know the basics of formatting using html, but I think basically it would be like:

Code:
		<div id="globalsearch" class="globalsearch">
<form action="http://www.midwiferyonline.co.uk/googlesearch.php" id="cse-search-box">
  <div>
    <input type="hidden" name="cx" value="partner-pub-XXXXXXXXXXXXXXXXXXXXXXXX" />
    <input type="hidden" name="cof" value="FORID:10" />
    <input type="hidden" name="ie" value="UTF-8" />
  <span class="textboxcontainer"><span>  <input type="text" name="q" size="20" /></span></span>
Midwifery Online <input type="radio" name="source" value="0"> WWW <input type="radio" name="source" value="1"> <span class="buttoncontainer"><span><input type="image" class="searchbutton" src="{vb:stylevar imgdir_button}/search<vb:if condition="$stylevar['textdirection'] == 'rtl'">_rtl</vb:if>.<vb:if condition="(is_browser('ie') AND !is_browser('ie', 7) AND !is_browser('ie', 8))">gif<vb:else />png</vb:if>" name="submit" onclick="document.getElementById('navbar_search').submit;" tabindex="100"/></span></span>
  </div>
</form>

I added the line in red. The maybe the code could be:

PHP Code:
if ($_REQUEST['source'] == 0

    
$vbulletin->url 'search.php?do=process&query=' urlencode($_REQUEST['q']); 
    
print_standard_redirect(''false); 

Reply With Quote
  #10  
Old 02-26-2012, 06:28 PM
deverill2010 deverill2010 is offline
 
Join Date: Jan 2011
Posts: 412
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Kh99, I tried it but both radio buttons still show results from the google search i.e the web. Just selecting my site doesn't use the sites search.
Any other ideas?

--------------- Added [DATE]1330284715[/DATE] at [TIME]1330284715[/TIME] ---------------

Sorry ignore that, I edited the wrong file.

If I tick my site for search and then search, it just gives me a blank page with this as the URL -

Code:
http://www.midwiferyonline.co.uk/googlesearch.php?cx=partner-pub-XXXXXXXXXXXXXXXX&cof=FORID%3A10&ie=UTF-8&q=study+day&source=0&submit.x=16&submit.y=18&siteurl=www.midwiferyonline.co.uk%2Fsearch.php%3Fsearchid%3D115155&ref=www.midwiferyonline.co.uk%252Fsearch.php%253Fsearchid%253D115154
And a blank page for the www search with this for the url -

Code:
http://www.midwiferyonline.co.uk/googlesearch.php?cx=partner-pub-XXXXXXXXXXXXXXXXXXXXXXXXXXX&cof=FORID%3A10&ie=UTF-8&q=study+day&source=1&submit.x=1&submit.y=9&siteurl=www.midwiferyonline.co.uk%2Fsearch.php%3Fsearchid%3D115155&ref=www.midwiferyonline.co.uk%252Fsearch.php%253Fsearchid%253D115154
?
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 On
HTML code is Off

Forum Jump


All times are GMT. The time now is 10:07 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.04200 seconds
  • Memory Usage 2,304KB
  • Queries Executed 12 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (5)bbcode_code
  • (3)bbcode_php
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (2)pagenav_pagelink
  • (10)post_thanks_box
  • (10)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (10)post_thanks_postbit_info
  • (10)postbit
  • (2)postbit_attachment
  • (10)postbit_onlinestatus
  • (10)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_attachment
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete