We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 6038
    • 228 Posts
    I'm just looking for clarification that the constraint field when creating a form customisation rule can NOT take comma separated values.
    I expected it would - but it seems not.

    There have been enthusiastically supported suggestions for it in the past:
    https://forums.modx.com/thread/29865/form-customization-improvement-suggestions#dis-post-161881

    But all I can find in the tracker is this dead feature request:
    http://tracker.modx.com/issues/19

    Am I right? It can't take a comma separated list of values?

    It would be dang handy to be able to pass multiple values eg
    constraint field: parent
    constraint values: 23,31,5 [ed. note: christianhanvey last edited this post 13 years, 2 months ago.]
      • 44665
      • 60 Posts
      sebastian-marinescu Reply #2, 13 years, 2 months ago
      Quote from: christianhanvey at Jul 31, 2013, 12:21 AM

      It would be dang handy to be able to pass multiple values eg
      constraint field: parent
      constraint values: 23,31,5

      Indeed it would! I almost asked the same question yesterday smiley
      I also tried putting in an array(1,2,3), and it also didn't work.

      Does anybody know if we can put multiple values into the constraint-value field?!
        • 3749
        • 24,544 Posts
        I think I put that in as a Feature Request a long time ago, but AFAIK, it has not been implemented. At the time, I verified that the code would only accept single values and I think that's still true. It should be easy to test if you have existing FC rules with constraints.
          Did I help you? Buy me a beer
          Get my Book: MODX:The Official Guide
          MODX info for everyone: http://bobsguides.com/modx.html
          My MODX Extras
          Bob's Guides is now hosted at A2 MODX Hosting
          • 6038
          • 228 Posts
          I didn't see your feature request when I was searching - so guess I'll create a new one.

          Actually, just found one, so gave it a nudge

          http://bugs.modx.com/issues/8336
            • 44665
            • 60 Posts
            sebastian-marinescu Reply #5, 13 years, 2 months ago
            Ok. It took me the night but I got it working - in alpha-mode.

            I updated the issue, where you can see the relevant codepart. But this is not properly tested code .. I already know it will crash, if you use something other than "parent" (or a couple others). Either we whitelist some constraint field keys for "multiple comma separated notation", or we use an array. As we see by Bob's Reference, no field expected is an array. So the use of an array would indicate multiple values.

            What do you think people? [ed. note: sebastian-marinescu last edited this post 13 years, 2 months ago.]
              • 3749
              • 24,544 Posts
              Looks like a good start. In theory, I think it would work on any field. It doesn't make much sense with some of them (e.g. properties), but I don't think anyone would try to use those anyway.

              The only issue is that no constraint value could have a regular comma in it. I'd suggest using || as a delimiter, which is much less likely to end up in a Resource field.

              A slightly different way to go would be to just explode all of them, whether they contain a delimiter or not. If there are no delimiters, the array will only have one member, but in_array() will still work.

              I'd also suggest using the strict comparison version of in_array():

              if (!in_array($obj->get($constraintField), $constraintValues), true)


              The loose version of in_array() can produce some very wacky results: http://www.php.net/manual/en/function.in-array.php#106319
                Did I help you? Buy me a beer
                Get my Book: MODX:The Official Guide
                MODX info for everyone: http://bobsguides.com/modx.html
                My MODX Extras
                Bob's Guides is now hosted at A2 MODX Hosting