Tags:
create new tag
view all tags

Question

I'd like to change the header on pages to have a Search button and a Go button, like http://www.wikipedia.org, so users don't have the extra step of having to click Search and THEN getting to do their search. I want a search box on every page, along with the ability to "go"/jump on every page, too.

To do this, I created a simple branching CGI script whose contents aren't meaningful here (I'll append them for the curious). I tested out the following code on a page in the Sandbox and it worked fine:

<form method="get" action="/cgi-bin/wiki/searchbox">
<input type="hidden" name="web" value="%WEB%" />
<input type="text" name="topic" size="16" />
<input type="submit" name="submit" value="Search" />
<input type="submit" name="submit" value="Go" />
</form>

However, when I inserted that into WebPreferences (so it would show up on each page), it should have searched, but instead insisted on going to the searched-for string as a topic name, which of course didn't exist and so produced the "the topic you are looking for does not exist, would you like to create it?" page. Looking at the rendered HTML I saw the following:

<a name="PageTop"></a>
<form name="main" action="/cgi-bin/wiki/view/Main/WebPreferences">
...
<td colspan="2">
Main . {  <form method="get" action="/cgi-bin/wiki/searchbox">... <input type="text" name="topic" size="16" /><input type="hidden" name="web" value="Main" /> <input type="submit" name="submit" value="Search" /> <input type="submit" name="submit" value="Go" /></form>  }
...
</form>

As you can see, the problem is a form-within-a-form, preventing the search box from submitting to a different location than the current topic page. I tried adding a name="main" to my form but that didn't work either. Any ideas? I'd really like to be able to make it so searching is not a two-step process, making it easy like Wikipedia does it.

  • TWiki version: 1 Feb 2003

Contents of my search/go branching CGI script, for the curious:

BEGIN { unshift @INC, '.'; require 'setlib.cfg'; }
use CGI::Carp qw(fatalsToBrowser);
use CGI;
use TWiki;
use strict;
my $cgiQuery = new CGI;
my $webName = $cgiQuery->param( 'web' ) || "";
my $searchFor = $cgiQuery->param( 'topic' ) || "";
my $submitButton = $cgiQuery->param( 'submit' ) || "";
if ($submitButton eq 'Go') {
    TWiki::redirect( $cgiQuery, &TWiki::getViewUrl( $webName, $searchFor ) );
} else {
    TWiki::redirect( $cgiQuery, &TWiki::getScriptUrl( $webName, "?scope=text&search=$searchFor", 'search') );
}

-- thanks, AnthonyRThompson - 22 Jul 2003

Answer

The WEBTOPICLIST is assumed to be used in a form, which the templates and skins do. You have to do one of:

  • Remove the form tag from all templates and skins; add your form tag to your WEBTOPICLIST
  • Change the form tag action in all templates and skins to your action
  • In WEBTOPICLIST, close the form tag first, then open your form tag

The TWiki core will be enhanced at some point to allow this. See also related PhotonSearch

-- PeterThoeny - 23 Jul 2003

I just did this, today. What I did was:

  • edit TWiki.WebTopBar to include my search code, preceeded by </form> and followed by <form> so there wouldn't be any HTML errors on the page.

My code looks like this:

</form> <!-- end Web Home form -->
<div class="twikiLeft">
<a href="%WIKILOGOURL%"><img src="%WIKILOGOIMG%" border="0" alt="Home"/></a>
</div>
<div class="twikiRight twikiSearchBox">
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<td>
<label for="go">Quick Search: </label>
<form action="%SCRIPTURLPATH%/search%SCRIPTSUFFIX%/%INTURLENCODE{"%INCLUDINGWEB%"}%/SearchResult">
<noautolink>
<input type="text" name="search" size="16" />  
  <input type="hidden" name="web" value="on" />
  <input type="hidden" name="scope" value="all" />
</noautolink>
</form>
</td>
</tr>
</table>
</div>

<form> <!-- make page's form opening/closing match up -->

-- DanielAllen - 02 Nov 2005

Do you mean like at the top of the LeftWebBar in Dakar:

  • ISW17.png:
    ISW17.png

-- AntonAylward - 02 Nov 2005

Edit | Attach | Watch | Print version | History: r4 < r3 < r2 < r1 | Backlinks | Raw View | Raw edit | More topic actions
Topic revision: r4 - 2005-11-02 - AntonAylward
 
  • Learn about TWiki  
  • Download TWiki
This site is powered by the TWiki collaboration platform Powered by Perl Hosted by OICcam.com Ideas, requests, problems regarding TWiki? Send feedback. Ask community in the support forum.
Copyright © 1999-2026 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.