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.
Warning: Can't find topic TWiki06x01.JSCalendarContribInline
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
--
MichaelCarter - 09 Sep 2008
Answer
If you answer a question - or someone answered one of your questions - please remember to edit the page and set the status to answered. The status selector is 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