![]() |
Radio Buttons for search
1 Attachment(s)
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"> PHP Code:
|
Anyone able to help me please as I'm stumped! :)
|
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.
|
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.
:( |
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.
|
Lol oops that's because it does..
Here's the template - Code:
{vb:stylevar htmldoctype} 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? |
You could try putting something like this near the beginning of your php script (maybe just under require_once('./global.php')):
PHP Code:
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. |
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. |
Well, I only know the basics of formatting using html, but I think basically it would be like:
Code:
<div id="globalsearch" class="globalsearch"> I added the line in red. The maybe the code could be: PHP Code:
|
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 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 |
Hmm...I threw together a test page based on your script and it seems to work. I'll post it in case it helps you somehow:
PHP Code:
|
I get
Parse error: syntax error, unexpected $end in /home/midwife/public_html/googlesearch.php on line 1 That when using that? |
Are you sure you got it all? Maybe you missed the } on the last line or something.
|
Sorry I'll try it again, im not that hot with this stuff. I appreciate your help honestly I do. This is something I have wanted for ages!
So the above code is meant to go where? replace my googlesearch.php? if so then what goes here - Code:
echo '<form action="test.php"> |
OK, I'm sorry, I wasn't very clear. That's just a test file, it shouldn't replace anything you have. Put it in a file called test.php, copy it to your forum directory, then go to it in your browser. When you press 'submit query' it should go to the forum search page or just print out "search google", depending on which radio button is selected. It's just supposed to show that the radio buttons and the redirect work.
|
And so it does lol.
Sorry for being a total dim ass. Why wont it work actually on the site then? I did have a play with this before several times and I just couldnt figure it out :( |
So you put this in your googlesearch.php just under the global.php require line?:
Code:
if ($_REQUEST['source'] == 0) If that's true, then temporarily change it to this: Code:
if (1 || $_REQUEST['source'] == 0) that should make it always go to your site search page. |
Just gives me a blank page again on both radio buttons with this as the url -
Code:
http://www.midwiferyonline.co.uk/googlesearch.php?cx=partner-pub-XXXXXXXXXXXXXXXXXXXX&cof=FORID%3A10&ie=UTF-8&q=help&source=0&submit.x=12&submit.y=17&siteurl=www.midwiferyonline.co.uk%2Fforum.php&ref=www.midwiferyonline.co.uk%2Fsearch.php%3Fsearchid%3D115193 Code:
<?php |
Well, I'm puzzled - it looks OK to me. Try commenting out the print_standard_redirect line (put // in front of it)
|
Ah!
Now my search is still giving me the blank page with the funny URL, even though I have removed the edits? My googlesearch.php is back to how it was and I have removed the bit from the template too..? |
Yeah, that's strange. There's got to be something wrong with that file, but I copied what you posted in the first post and it works for me.
What program are you using to edit your files? |
Notepad++
I have recopied what I put in my very first post which was my original file, but its still showing me a blank page with all the funny stuff in the url. *Shrugs Shoulders* It worked fine before we started playing with it hahaha! |
That stuff in the url I think is normal, because the search forum uses the "GET" method which puts all the info on the url. Hate to ask, but are you sure you're editing the correct file? (you said earlier that you edited the wrong one).
Also, if you have access to your web server error logs, check there. Oh - another thing you could try, edit that file and put Code:
die("This is a test"); right under the <?php at the top and see if you get that message. |
Haha yep right file.
If I add that bit of code I get this when doing a search - Fatal error: Call to undefined function phpdie() in /home/midwife/public_html/googlesearch.php on line 1 |
OK, that confirms that it's the correct file. The error looks like you just have no space between the <?php and the die(). (or if you do, maybe it's a clue to the problem). Do you have a windows server by any chance? And I assume you're editing on your local computer and uploading it? Maybe it's a problem with ftp settings.
|
Hmm Dunno I have had to revert back to the standard search, so never mind.
|
All times are GMT. The time now is 04:47 AM. |
Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
![]() |
|
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|