We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 14883 ☆ A M B ☆
    • 450 Posts
    It seems that FormItIsSelected and FormItIsChecked have an undocumented (at least on the RTFM pages) feature: you can pass a comma-delimited list of values, and if any of them are matched, the snippet call will return positive (set the 'select' or 'checked' value).

    This is cool, but... what if my actual value has a comma in it?

    <input type="checkbox" name="times[]" value="Monday, AM" [[!+fi.times:FormItIsChecked=`Monday, AM`]] >
    <input type="checkbox" name="times[]" value="Monday, PM" [[!+fi.times:FormItIsChecked=`Monday, PM`]] >
    <input type="checkbox" name="times[]" value="Tuesday, AM" [[!+fi.times:FormItIsChecked=`Tuesday, PM`]] >  


    In this case, the snippet call does not return a match (because, of course, it is exploding the input string and trying to match EITHER 'Tuesday' OR ' PM').

    I suppose commas in form element values are somewhat rare, but surely they aren't unheard of.

    My first thought on a fix was to use something less likely to be in a form value, like a double bar '||'.

    But my next thought was, it probably isn't good form to rely on the relative obscurity of the chosen delimiter. No matter how obscure, someone's eventually gonna have that in their form value, and is gonna be confused that the snippet isn't working right.

    Maybe provide a way for the user to specify their own delimiter? So they can pick one they are sure won't show up in their values?

    Or maybe there's a better way than that, even? [ed. note: jrotering last edited this post 13 years, 8 months ago.]
      • 14883 ☆ A M B ☆
      • 450 Posts
      Okay, so, I was entirely wrong about the "undocumented feature". I mis-read the source code.

      The value of the placeholder itself (+fi.times in this case) is a comma-delimited list. The snippets explode THAT list and see if the value passed in matches any of the array values.

      So... is there a way to modify FormIt to allow for commas in field values?
        • 14883 ☆ A M B ☆
        • 450 Posts
        I spent some time on this today, found a clean way to fix the problem, and submitted a pull request to the FormIt project on github.

        Rather than encoding the original PHP array of (checkbox/select) values as a comma-delimited list, then exploding it, I used JSON. This prevents any risk of a delimiter that might appear in a form value.