SID-01291: IF statement in Search format
Status: |
Answered |
TWiki version: |
5.0.1 |
Perl version: |
Perl 5.8 |
Category: |
CategoryAPI |
Server OS: |
Ubuntu 8.04 |
Last update: |
12 years ago |
I want to make search result, depending on form field value.
I tried:
format="%IF{"$formfield(Title)==''" then="$topic" else="$formfield(Title)"}%
I always get $topic values, should also get some formfield values.
How do i compare that formfield value?
--
BostjanTovornik - 2011-10-11
Discussion and Answer
You need to escape the IF or it gets evaluated once before the SEARCH. You also need to escape the double quotes:
format="$percntIF{\"'$formfield(Title)'=''\" then=\"$topic\" else=\"$formfield(Title)\"}$percnt
Details in
FormattedSearch and
IfStatements.
--
PeterThoeny - 2011-10-11
I get errors like this:
IF{ "Vprašanja in predlogi==''" else="Vprašanja in predlogi" then="VprasanjaPredlogi" }: Syntax error in 'Vprašanja in predlogi==''' at 'šanja in predlogi=='''
IF{ "==''" else="" then="WebSearch" }: Excess operators (= =) in '=='''
Is that result of state, that $formfield(Title) doesn't exist? Or what seems to be the problem...
--
BostjanTovornik - 2011-10-12
You need to compare a 'string' with another 'string', e.g.
" 'a'='b' "
. I fixed my example above.
--
PeterThoeny - 2011-10-12
Closing this question after more than 30 days of inactivity. Feel free to reopen if needed. Consider engaging one of the
TWiki consultants if you need timely help. We invite you to
get involved with the community, it is more likely you get community support if you support the open source project!
--
PeterThoeny - 2012-01-23
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.