Tags:
create new tag
, view all tags

Question

How do I perform a search that uses a value the user entered into a form? For example, for my TWiki installation every project my team is working has it's own topic. In the search below I search for all completed projects that were deployed to our prod environment on or after 2008-08-01 (August 8th, 2008). I would like to create an html form where the user can enter a date into a text box and click a search button. Whatever date the user entered would be subsituted for 2008-08-01 in the search example below.

%SEARCH{"ProjectForm.ProjectStatus = 'Complete' AND parent.name = 'ProjectsHome' AND ProjectForm.ActualProdDeployDate >= '2008-08-01'" web="Main" type="query" order="formfield(ActualProdDeployDate)" nosearch="on" nototal="on"
     header="| *Project Name* | *Effected Application* | *Lead* | *Project Status* | *Actual Prod Deployment Date* | *Comments* |"
     format="| $topic | <nop>$formfield(Application) | $formfield(ProjectLead) | <nop>$formfield(ProjectStatus) | $formfield(ActualProdDeployDate) | $formfield(Comments) |"}%

This is what I have for the text box and search button so far.

Enter Date:

I don't know how to set this up so when the user clicks the search button the search is performed. I appreciate all the help! Thanks!

Environment

TWiki version: TWikiRelease04x02x00
TWiki plugins: SpreadSheetPlugin, ActionTrackerPlugin, CommentPlugin, EditTablePlugin, InterwikiPlugin, PreferencesPlugin, SlideShowPlugin, SmiliesPlugin, TablePlugin, TinyMCEPlugin, TwistyPlugin, WysiwygPlugin
Server OS: Ubuntu 7.10
Web server: Apache 2.2.4
Perl version: Perl 5.8.8
Client OS: Windows XP
Web Browser: IE 6
Categories: Search

-- MichaelCarter - 09 Sep 2008

Answer

ALERT! If you answer a question - or have a question you asked answered by someone - please remember to edit the page and set the status to answered. The status is in a drop-down list below the edit box.

You're almost there. I didn't change your form at all, but now it works (try entering a date!):

To use 2008-08-01 as a default search value, just put the following line in the topic that's the target of the action, and hide it in HTML comment tags:

   * Set USERDATE = %IF{"defined UserDte" then="%URLPARAM{UserDte}%" else="2008-08-01"}% 

Then this ...

   %SEARCH{...Date >= '%USERDATE%'}% 

... will render like this [the date in the next line is controlled by your form] ...

   %SEARCH{...Date >= '2008-08-01'}% 

... which will do the search (once you remove the "pre" tags).

You could put the %IF{...}% inside the %SEARCH{...}%, but I like to break it out with its own variable like that for readability/maintainability.

See VarIF and IfStatements for more information and options. E.g., you might prefer to not search until a date is entered:

   %IF{"defined UserDte" then="Search: %URLPARAM{UserDte}%" else="No search passed in"}%

Which goes something like this [the text of the next line is also controlled by your form]:

   No search passed in

-- SeanCMorgan - 09 Sep 2008

Thank you Sean! I couldn't figure out what the syntax or logic I needed to setup a variable that had a value of the date entered on the form. Your IF suggestion in the HTML comment tags did the trick.

Now that I can do this I can create a topic that has various text boxes. Management or anyone else can enter search criteria into these text box and click a Search button to get their specific results. Thanks again!

-- MichaelCarter - 10 Sep 2008

I'm glad to help.

I'm still impressed with how easy it is to build an application with TWiki.

-- SeanCMorgan - 11 Sep 2008

 
Change status to:
Topic revision: r4 - 2008-09-11 - SeanCMorgan
 
Twitter Delicious Facebook Digg Google Bookmarks E-mail LinkedIn Reddit StumbleUpon    
  • Download TWiki
TWiki logo Powered by Perl Hosted by OICcam.com Ideas, requests, problems regarding TWiki? Send feedback. Ask community in the support forum.
Copyright © 1999-2012 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.