create new tag
, view all tags

SID-02185: If Formfield Blank then do nothing

Status: Answered Answered TWiki version: Perl version:
Category: Server OS: CentOS 5.2 Last update: 6 months ago

I've been trying to figure out how to get the If then else to work using the variable formfield().

My goal is to have an if statement that will execute a search query as long as a specific formfield is not blank in a form. However, no matter how I try to pass in the formfield variable as $formfield(Fieldname) or %FORMFIELD{"Fieldname"}% to equal <NOP> it's not working. I've also tried '$formfield{Fieldname}' from the Ifstatements topic.

My If statement below. I can replace formfield portion of the code with 0=0 and it will execute fine so I must not be passing in or using the correct parameter for the formfield. Any recommendations?

%<NOP>IF{"'$FORMFIELD{Sat OPS Branch Code}'=''<NOP>" then="<NOP>" else="%SEARCH{ web="ADB" "[F]orm Field.*value\=.%FORMFIELD{"Sat OPS Branch Code"}%" scope="text" topic = "DLPID*" type="regex" nosearch="on" order="formfield(Name)" nototal="on" format="| $formfield(fieldname) | $formfield(fieldname) | $formfield(fieldname) | $formfield(fieldname) | $formfield(fieldname) | $formfield(fieldname) | $formfield(fieldname) | $formfield(Item Type) | $formfield(Currently Assigned User) | View / Edit |" }%"}%

-- Christopher Crowe - 2016-04-05

Discussion and Answer

TWiki evaluates variables inside-out and left-to-right by default. In your case, SEARCH is evaluated before the IF, which is not what you want. You need to escape the SEARCH in the else="", using $percnt for %, and \" for quotes, such as else="$percntSEARCH{ web=\"ADB\" ... }$percnt". Details in VarIF and IfStatements.

-- Peter Thoeny - 2016-04-06

Thanks Peter, the escape of the search string helped me reduce my issue to the condition. Apparently the statement i'm using %IF{"%FORMFIELD{"Sat OPS Branch Code"}%='<NOP>'" evaluates to ='' so I receive the error that I have Excess operators. It doesn't like if blank = blank and that's not what I wanted to accomplish. I'm using the wrong variable to reference a formfield name.

What is the proper way to call a formfield name so that IF{"formfield name = blank/no value" then else} ?

I've done quite a bit a searching on this one and the closest thing I found was the use of %FORM; however, that variable just comes out as plain text.

-- Christopher Crowe - 2016-04-07

With IF you should be able to compare empty strings. Let's test:

  • |%IF{ "''=''" then="empty is equal empty" else="empty is not equal empty" }%| MOVED TO... |empty is equal empty|
  • |%IF{ "'XYZ'='XYZ'" then="XYZ is equal XYZ" else="XYZ is not equal XYZ" }%| MOVED TO... |XYZ is equal XYZ|

-- Peter Thoeny - 2016-04-07

On your case, you want to evaluate FORMFIELD before the IF so that IF can make the right choice. That is do not escape FORMFIELD in the IF test. However, you need to escape the SEARCH in the else part so that it evaluates after the IF test.

-- Peter Thoeny - 2016-04-07

I realize what I had done. I was trying to use <NOP> for the blank instead of just leaving it blank, so it was breaking the string. I thought i had tried just leaving it blank before, but i may not have escaped the search string at that time. Thanks for all of your help!

Wrong format: %IF{"%FORMFIELD{"fieldname"}%='<NOP>'" then=" " else=" "}

Working format: $IF{"%FORMFIELD{"fieldname"}%=''" then=" " else=" "}

-- Christopher Crowe - 2016-04-07

I suppose the operator '=' compares two strings which should be placed in ' '. So the working format should be: %IF{'"%FORMFIELD{"fieldname"}%'=''" then="empty" else="not empty"}.

-- Emiel Van Riel - 2017-09-25

      Change status to:
ALERT! 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.
Status Answered
Title If Formfield Blank then do nothing

TWiki version

Server OS CentOS 5.2
Web server Apache/2.0.52
Perl version

Browser & version IE 11 / Chrome 45.0.2454.101 m
Edit | Attach | Watch | Print version | History: r6 < r5 < r4 < r3 < r2 | Backlinks | Raw View | Raw edit | More topic actions
Topic revision: r6 - 2017-09-25 - EmielVanRiel
  • 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-2018 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.