Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using || OR in coldfusion if statement with isDefined

I am using session variables in Coldfusion 2018 and I am trying to figure out how to add a variable with the way my if statements are set up.

<cfif isDefined("session")
            and structKeyExists(session, 'checkout')
                and structKeyExists(session.checkout, 'info')
                    and structKeyExists(session.checkout.info, 'andor_1') >
        <cfif session.checkout.info.andor_1 eq "And">
      <strong>- All signatures are required.</strong>
      </cfif>
      </cfif>

or 

<cfif isDefined("session")
            and structKeyExists(session, 'checkout')
                and structKeyExists(session.checkout, 'info')
                    and structKeyExists(session.checkout.info, 'bandor_1') >
        <cfif session.checkout.info.bandor_1 eq "And">
      <strong>- All signatures are required.</strong>
      </cfif>
      </cfif>

The if statements are almost identical andor_1 or bandor_1 but either one might not always exist which is why I am using the isDefined.

I have tried using || and or.

 <cfif isDefined("session")
                and structKeyExists(session, 'checkout')
                    and structKeyExists(session.checkout, 'info')
                        and structKeyExists(session.checkout.info, 'andor_1') 
|| isDefined("session")
                and structKeyExists(session, 'checkout')
                    and structKeyExists(session.checkout, 'info')
                        and structKeyExists(session.checkout.info, 'bandor_1')>
            <cfif session.checkout.info.andor_1 eq "And" || session.checkout.info.bandor_1 eq "And">
          <strong>- All signatures are required.</strong>
          </cfif>
          </cfif>

Any help combining these cfifs would be greatly appreciated.

like image 523
David Brierton Avatar asked Dec 18 '25 08:12

David Brierton


1 Answers

The correct way in CF is 'OR' as opposed to ||.

However, in your first example you've place the "OR" outside of your IF statements. Try this:

 <cfif isDefined("session") AND structKeyExists(session, 'checkout') AND structKeyExists(session.checkout, 'info')
                AND (
                        (structKeyExists(session.checkout.info, 'andor_1') AND session.checkout.info.andor_1 eq "And")
                        OR
                        (structKeyExists(session.checkout.info, 'bandor_1') AND session.checkout.info.bandor_1 eq "And")
                    )>

     <strong>- All signatures are required.</strong>
</cfif>
like image 120
CFMLBread Avatar answered Dec 20 '25 02:12

CFMLBread



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!