Skip to main content.
home | support | download

Back to List Archive

Re: default reverse sort in swish.cgi

From: Bill Moseley <moseley(at)>
Date: Tue Sep 21 2004 - 02:02:54 GMT
On Mon, Sep 20, 2004 at 03:46:52PM -0700, Alex L. wrote:
> Hello,
> What is the best way to set Reverse Sort checked by
> default from swish.cgi, can that be configured in 
> swishcgi.conf?

You want the long answer or the short answer?  Oh, wait, I never give
the short answer.

The long answer is that check boxes send checked when they are on, and
when they are off they send, well, nothing.  So, you need to save state
somehow.  The Perl CGI module does this by including a hidden field
called ".cgifields" -- but only if you use all the cgi form widgets
which swish.cgi doesn't do by default.

CGI creates the .cgifields when you use the $cgi->end_form method, but
swish.cgi simply uses </form>.  So to use the CGI module's method of
sticky forms with a default check you need to modify the template
generation code.

Assuming you are using to generate the HTML for the
form,  you would need to replace the </form> with a call to the CGI
method end_form().  See below for the diff of this change plus the
change to the checkbox wigdet to set the default.

Now, you asked if it could be done in .swishcgi.conf.  Yes, it can be,
I suppose.  What you want to do is set it checked if it's the first
time the form is displayed -- i.e. not after it's been submitted.

There's an undocumented config option that provides a hook into the
request before anything has been done with it.

Ok, so here's the short answer after all:

return {
    request_fixup => sub {
        my ( $cgi, $conf ) =@_;
        $cgi->param('reverse', 'on') unless $cgi->param('submit');

Is it clear to you what that code does?

Here's that diff if you want to hack the template module.

Index: modules/SWISH/
RCS file: /cvsroot/swishe/swish-e/example/modules/SWISH/,v
retrieving revision 1.3
diff -u -B -r1.3
--- modules/SWISH/    13 May 2003 06:11:33 -0000      1.3
+++ modules/SWISH/    21 Sep 2004 01:39:09 -0000
@@ -122,7 +122,7 @@
                  : join "\n", map { $q->hidden($_) } @$extra; 
+    my $end_form = $q->end_form;
     return <<EOF;
     <form method="get" action="$form" enctype="application/x-www-form-urlencoded" class="form">
         <input maxlength="200" value="$query" size="32" type="text" name="query"/>
@@ -130,7 +130,7 @@
         <input value="Search!" type="submit" name="submit"/><br>
-    </form>
+    $end_form
@@ -399,7 +399,8 @@
             -name   => 'reverse',
-            -label  => 'Reverse Sort'
+            -label  => 'Reverse Sort',
+            -checked => 1,

Bill Moseley

Unsubscribe from or help with the swish-e list:

Help with Swish-e:
Received on Mon Sep 20 19:03:43 2004