We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 32678
    • 290 Posts
    I have a Formit agreement form a user needs to pass through to access information. The form redirects to the information resource, and there a cookie stores the agreement validation. If the user logs out and revisits the site, I want to bypass the agreement form and redirect to the info resource.

    I'm using cookieJar, If, and a redirect snippet for this. If detects the cookie value, but the redirect snippet executes regardless of the If condition.

    I've used both Redirectoid and the GotoURL snippet (not in the extras repository, but on Github (https://gist.github.com/intersel/442a55761b6df02334590f4db0bd2abe). The latter has a true / false parameter, where true means do nothing -- this is what I have in use below.

    Any thoughts on this? FWIW, this is the current If usage (I've gone through a few iterations):

    [[!If? &subject=`[[!getCookie? name=`fmr_Agr`]]` &operator=`EQ` &operand=`valid` &then=`[[GotoURL? &gotoURL=`13` &dontGoto=`0`]]` &else=`[[GotoURL? &gotoURL=`13` &dontGoto=`1`]]`]]

    This question has been answered by Bruno17. See the first response.

    • discuss.answer
      • 4172
      • 5,888 Posts
      Your snippet gets allways executed.
      Try it this way:

      [[[[!If? &subject=`[[!getCookie? name=`fmr_Agr`]]` &operator=`EQ` &operand=`valid` &then=`!GotoURL? &gotoURL=`13` &dontGoto=`0`` &else=`!GotoURL? &gotoURL=`13` &dontGoto=`1``]]]]


      Then only the then or the else-part gets executed
        -------------------------------

        you can buy me a beer, if you like MIGX

        http://webcmsolutions.de/migx.html

        Thanks!
        • 32678
        • 290 Posts
        Quote from: Bruno17 at Feb 09, 2017, 02:24 PM
        Then only the then or the else-part gets executed

        Thanks Bruno. Is this specific to the If snippet, or just how the modX parser works?
          • 4172
          • 5,888 Posts
          This has todo with the parsing-order of MODX-tags.
          The parsers parses from inside to outside.
          As soon as the parser sees the snippet-tag
          [[GotoURL? &gotoURL=`13` &dontGoto=`0`]]
          it will execute the snippet.

          But, if you do it the other way, it will first execute the If - snippet, which results in
          !GotoURL? &gotoURL=`13` &dontGoto=`0`


          In the next parsing-loop, the parser sees only the remaining snippet-tag
          [[!GotoURL? &gotoURL=`13` &dontGoto=`0`]]
          or
          [[!GotoURL? &gotoURL=`13` &dontGoto=`1`]]
            -------------------------------

            you can buy me a beer, if you like MIGX

            http://webcmsolutions.de/migx.html

            Thanks!
            • 4172
            • 5,888 Posts
            you could do it also this way:

            [[!GotoURL? &gotoURL=`13` &dontGoto=`[[!If? &subject=`[[!getCookie? name=`fmr_Agr`]]` &operator=`EQ` &operand=`valid` &then=`0` &else=`1`]]`]]
              -------------------------------

              you can buy me a beer, if you like MIGX

              http://webcmsolutions.de/migx.html

              Thanks!
              • 32678
              • 290 Posts
              Bruno, thanks for the explanations -- very helpful and much appreciated.