DokuWiki

It's better when it's simple

User Tools

Site Tools


plugin:searchformgoto

This is an old revision of the document!


searchformgoto plugin

Compatible with DokuWiki

"Binky"

plugin A plugin for DokuWiki which allows adding a "Go" button to the search form that will go directly to a page if the search exactly matches a page name. Otherwise operates as a normal search.

Last updated on
2014-01-04
Provides
Action

This extension has not been updated in over 2 years. It may no longer be maintained or supported and may have compatibility issues.

Similar to singlesearchresult

Tagged with redirect, search

How to use

You have to modify your template to use this plugin. Edit <dokuwiki home>/lib/tpl/<your template>/main.php and replace the line:

<?php tpl_searchform() ?>

With:

<?php if (!plugin_isdisabled('searchformgoto')) {
	$searchformgoto = &plugin_load('helper','searchformgoto');
	$searchformgoto->gotoform();
	} else { tpl_searchform(); }
?>

Download and Installation

Download and install the plugin using the Plugin Manager using the following URL. Refer to Plugins on how to install plugins manually.

Change log

  • danny0838's solution was integrated — S.C. Yoo 2014/01/04 16:34

Discussion


As of right now this doesn't work with a fresh install?

Fatal error: Call to undefined function tpl_gotoform()
I can't do it, not call tpl_gotoform with plugin installed
Is there other TODO ?
I'm not sure I understand your problem. It works fine in the installs I've done. Can you describe your issue in more detail? -Payton

I'd love to use this plugin, but the template I'm using (Monobook) uses a different piece of script for the search bar. I'm comfortable enough with searching and replacing lines of code when necessary, but I'm a newbie and *adapting* code is a little beyond me. Is there any way to turn the following searchform code into something that also works with your plugin?
> <?php if (tpl_getConf('mb_use_search')) { ?>
><div id="p-search" class="portlet">
>    <h5>
>        <label><?php echo $lang['monobook_bar_search']?></label></h5>
>    <div class="pBody">
>        <form action="<?php echo DOKU_BASE.DOKU_SCRIPT;?>" accept-charset="utf-8" id="dw__search" name="search">
>            <input type="hidden" name="do" value="search" />
>            <input id="qsearch__in" name="id" type="text" accesskey="f" value="" />
>            <input type='button' class="searchButton" id="searchGoButton" value="<?php echo >$lang['monobook_btn_go']?>" onclick="document.location.href='<?php echo DOKU_BASE.DOKU_SCRIPT;?>?id=' + >document.search.qsearch__in.value;" />&nbsp;
>            <input type='submit' name="fulltext" class="searchButton" value="<?php echo >$lang['monobook_btn_search']?>" />
>        </form>
>    </div>
></div>
Sorry if this is a dumb question. Thanks in advance!
Alan Gratz
Hm. It looks like that template defines its own search form entirely. I'm not entirely sure what that template is doing with the form, but here's two suggestions to try:
1. Replace all of the above code within the <div> tags with 'tpl_gotoform();'
2. [This one might be better] Add the following lines near the end of your template form (you may need to remove the hidden “do” input you already have):
         
<input type="hidden" name="do" value="goto" />
<input type="hidden" name="current_ns" value="'.$ns.'" />
<input type="submit" value="'.$lang['btn_go'].'" class="button" name="goto" title="'.$lang['btn_go'].'" />

-Payton


Unfortunately, I get “undefined function tpl_gotoform” with the “simple” template.

Thanks,
Kingsley

For the issue of undefined function tpl_gotoform a little patch could be done:

  • Delete line 35, and 38-63 in action.php:
line-35
        $contr->register_hook('TPL_ACT_RENDER', 'BEFORE', $this, 'handle_act_render', array());
line-38-63
    function handle_act_render(&$event, $param) {
    ...
    }
  • Add a file helper.php:
helper.php
<?php
/**
 * Searchformgoto Plugin
 *
 * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
 * @author     Payton Swick <payton (at) foolord (dot) com>
 */
 
// must be run within Dokuwiki
if(!defined('DOKU_INC')) die();
 
class helper_plugin_searchformgoto extends DokuWiki_Plugin {
 
    function gotoform($ajax=true,$autocomplete=true) {  
        global $lang;
        global $ACT;
        global $ID;
        // don't print the search form if search action has been disabled  
        if (!actionOk('search')) return false;
 
        print '<form action="'.wl().'" accept-charset="utf-8" class="search" id="dw__search"><div class="no">';
        print '<input type="hidden" name="do" value="goto" />';
        print '<input type="hidden" name="current_ns" value="'.cleanID(getNS($ID)).'" />';  
        print '<input type="text" ';
        if($ACT == 'search') print 'value="'.htmlspecialchars($_REQUEST['id']).'" ';  
        if(!$autocomplete) print 'autocomplete="off" ';
        print 'id="qsearch__in" accesskey="f" name="id" class="edit" title="[F]" />';  
        print '<input type="submit" value="'.$this->getLang('btn_go').'" class="button" name="goto" title="'.$this->getLang('btn_go').'" />';
        print '<input type="submit" value="'.$lang['btn_search'].'" class="button" name="goto" title="'.$lang['btn_search'].'" />';
        if($ajax) print '<div id="qsearch__out" class="ajax_qsearch JSpopup"></div>';
        print '</div></form>';
        return true;
    }	
}
  • Write this in the template where you want to display the search box (commonly replace tpl_searchform()):
<?php if (!plugin_isdisabled('searchformgoto')) {
	$searchformgoto = &plugin_load('helper','searchformgoto');
	$searchformgoto->gotoform();
	} else { tpl_searchform(); }
?>

— danny0838 2010/12/27 13:32

plugin/searchformgoto.1388850013.txt.gz · Last modified: 2014-01-04 16:40 by goldseed

Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Share Alike 4.0 International
CC Attribution-Share Alike 4.0 International Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki