PDA

View Full Version : How can I add a search widget to my vb 4 cms?


metalguy639
10-12-2011, 01:42 PM
I need to create a search widget for my vb4 cms. I tried just copying and pasting the search box code into a html widget and it does not process the special vb raw codes. So I need to know how to add the search box that members can use to search the site with. Thanks

kh99
10-12-2011, 02:01 PM
Maybe you could create a new template and put the search box code in it, then write a php widget to render the template. Here's an article about rendering templates: https://vborg.vbsupport.ru/showthread.php?t=228078 , you should be able to copy code from that and modify it. (For a php widget you'd want to set $output to the result of the call to render() ).

metalguy639
10-12-2011, 10:16 PM
YUCK! Sorry that is way more involved than I wanted. I'm not a php programmer so some of that stuff makes no sense to me. There is not a widget already done for this somewhere? I find it hard to believe that no one has done one yet. I searched for hours but could not find anything.

kh99
10-12-2011, 10:35 PM
I really don't know if one exists or not, but if you post the search form code you found I'll see if I can do the php for it.

metalguy639
10-12-2011, 11:05 PM
I took the navbar search code because I wanted it to basically be like the navbar but just in a widget.

<vb:if condition="$vboptions['enablesearches']">
<div id="globalsearch" class="globalsearch">
<form action="search.php?{vb:raw session.sessionurl}do=process" method="post" id="navbar_search" class="navbar_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" />
<span class="textboxcontainer"><span><input type="text" value="" name="query" class="textbox" tabindex="99"/></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>
</form>
<ul class="navbar_advanced_search">
<li><a href="search.php{vb:raw session.sessionurl_q}" accesskey="4">{vb:rawphrase advanced_search}</a></li>
</ul>
</div>
</vb:if>

Thanks

kh99
10-13-2011, 12:11 AM
OK, well, it basically works but there's problems with the formatting and I'm not really big on CSS. I had to take out some of the classes to get it to look right, and I had to change the submit button to a standard button because for some reason the image wouldn't show up (even though it showed exactly the same path as the one in the navbar :confused:). Anyway, I created a new template named search_widget with this code:

<div id="globalsearch_widget">
<form action="search.php?{vb:raw session.sessionurl}do=process" method="post" id="search_widget">
<input type="hidden" name="securitytoken" value="{vb:raw bbuserinfo.securitytoken}" />
<input type="hidden" name="do" value="process" />
<span class="textboxcontainer"><span><input type="text" value="" name="query" class="textbox" tabindex="99"/></span></span>
<span class="buttoncontainer"><span><input type="submit" name="submit" value="Search" tabindex="100"/></span></span>
</form>
<a href="search.php{vb:raw session.sessionurl_q}" accesskey="4">{vb:rawphrase advanced_search}</a>
</div>


and then created a new "php direct execution" widget, and in the configuration I inserted this (replace the code that's already there)

$templater = vB_Template::create('search_widget');
$output = $templater->render();


and I set the cache refresh time to 0 (you could probably set it to something high so it doesn't refresh since it never changes, but then when you want to work on it it's annoying). Also, naming the template search_widget makes it go inside the "Search Templates" group in the style manager template list, so if you don't want that you could name it something else (and change it in the php code as well).

Anyway, it's not just like the navbar so I realize it's not exactly what you wanted, but maybe you can figure out the formatting.

metalguy639
10-13-2011, 01:23 AM
Awesome! That has worked perfectly! Thanks so much :)