PDA

View Full Version : Adding Search Specific Forum Option


Black Snow
02-16-2013, 05:11 PM
Hi,

I didn't want to bump an old thread so I thought I would create a new one.

I am trying to create a search function, similar to the one used here, where a member can search specific forums. Just like this post (https://vborg.vbsupport.ru/showthread.php?t=271503), I have found the forumchoice[] is not working on 4.2.0.

I have titleonly working, as it will only show me threads that have the search term(s) in their title but it will not search in a specific forum.

Here is my current code.
<form action="search.php?{vb:raw session.sessionurl}do=process" method="post" id="footer_search" class="footer_search">
<vb:comment><input type="hidden" name="s" value="{vb:raw session.sessionurl}" /></vb:comment>
<input type="hidden" name="securitytoken" value="{vb:raw bbuserinfo.securitytoken}" />
<input type="hidden" name="do" value="process" />

<input type="text" value="" name="query" class="textbox" tabindex="99" />
<select name="forumchoice[]">
<option value="-1" selected="selected">All Forums</option>
<option value="1">Forum 1</option>
<option value="2">Forum 2</option>
<option value="3">Forum 3</option>
<option value="4">Forum 4</option>
<option value="5">Forum 5</option>
</select>
<select name="titleonly">
<option value="0" selected="selected">All Posts</option>
<option value="1" >Titles Only</option>
</select>
<input type="image" class="searchbutton" src="{vb:stylevar imgdir_button}/search<vb:if condition="$stylevar['textdirection'] == 'rtl'">_rtl</vb:if>.png" name="submit" onclick="document.getElementById('navbar_search').submit;" tabindex="100"/>

</form>
I would love some help if anyone has any suggestions.

Black Snow
02-17-2013, 05:57 PM
Anyone help me with this?

Black Snow
02-18-2013, 05:59 PM
Surely someone knows how I can fix this issue? I've been trying everything I can find on the forums to fix this problem.

Seems like nobody wants to help when it comes to making something that looks like or works like something here on vB.org.

Black Snow
03-05-2013, 09:25 AM
Bah, guess I'll have to ask for help from somewhere else then.

Skyrider
07-28-2014, 06:43 PM
Having the same issue :-\ been googling for hours.. Just can't get forumchoice[]=xx or forumchoice=xx to work. Search results works fine, it refuses to use the specified Forumchoice (forum section) though. It searches forum-wide instead.

kh99
07-28-2014, 08:28 PM
Hmm...well, here's a list of what's being posted when I search from the search page using "single content type" of post and selecting some forums:

titleonly=0
searchuser=
starteronly=0
tag=
forumchoice%5B%5D=5
forumchoice%5B%5D=6
forumchoice%5B%5D=7
forumchoice%5B%5D=8
childforums=1
replyless=0
replylimit=
searchdate=0
beforeafter=after
sortby=dateline
order=descending
showposts=0
saveprefs=1
dosearch=Search+Now
searchthreadid=
s=
securitytoken=1406582637-cf67eb3a60e2ff5376b1527b3643f4ef0f2351cb
searchfromtype=vBForum%3APost
do=process
contenttypeid=1


So I'm guessing that the forumchoice[] fields are only used if some other option is set to a certain value (but sorry, I don't have time right now to figure out which one - maybe you can experiment).

Edit: glancing at the list, most of them are just options that I wouldn't think would affect whether or not forumchoice[] is used, so it seems like maybe you need do=process, contenttypeid=1, and/or dosearch=Search+Now.

tbworld
07-28-2014, 09:06 PM
Attach a functional page of code that I can test as a PHP file (so I do not have to create it myself) and I will be glad to take a look at it. :)

Skyrider
07-29-2014, 09:44 AM
Attach a functional page of code that I can test as a PHP file (so I do not have to create it myself) and I will be glad to take a look at it. :)
I'm using a search code in a template though, for example:

<a href="/search.php?do=finduser&userid={vb:raw post.userid}&contenttype=vBForum_Threads&showposts=0&forumchoice=35&forumchoice[]=35">test</a>

Using both forumchoice / forumchoice[] to make sure it "works", though it doesn't. Even when I use them separately.

kh99
07-29-2014, 10:16 AM
It does seem like forumchoice[] should work. "include" works, if what you're doing is coding a link like in your example, but it's a comma-separated list of ids so it wouldn't work with an option list (like the OP was asking about).

Skyrider
07-29-2014, 10:22 AM
So you are saying I can't get a section-search to work through a text link url search?

kh99
07-29-2014, 10:32 AM
I was saying that if you change forumchoice[]=35 to include=35 it will work.

Edit: oops, forget that last part I wrote, I got myself confused by not refreshing my browser page. But looking at the search code, it seems like it might have something to do with how the content type is specified.

Edit again: OK, I'm pretty sure that this works:
<a href="search.php?do=finduser&userid={vb:raw post.userid}&contenttypeid=1&showposts=0&forumchoice[]=22">test</a>

Skyrider
07-29-2014, 11:06 AM
I was saying that if you change forumchoice[]=35 to include=35 it will work.

Edit: oops, forget that last part I wrote, I got myself confused by not refreshing my browser page. But looking at the search code, it seems like it might have something to do with how the content type is specified.

Edit again: OK, I'm pretty sure that this works:
<a href="search.php?do=finduser&userid={vb:raw post.userid}&contenttypeid=1&showposts=0&forumchoice[]=22">test</a>
I'm in love with you right now, thanks! So it was just the "contentid" with value 1 that had to be added? I assume I can add multiple forumchoices as well to search through multiple forum sections?

kh99
07-29-2014, 12:21 PM
I didn't try that, but you should be able to. I believe it's done by adding additional parameters, like:
...&forumchoice[]=22&forumchoice[]=23&forumchoice[]=24

BTW, I noticed my post above could be confusing because I edited and removed a paragraph, but just to be clear, using include=35 should also work, even without the contenttypeid. But in that case specifying multiple forums would be like this: include=22,23,24. So that will work with a link (and the resulting link is easier to read) but to have a form with a list to select from (like the OP wanted) then you need to use forumchoice[]. (I hope that makes sense).