We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 24287
    • 14 Posts
    Hi,

    I’m trying to use the new FormIt 1.6.0 Checkbox feature on a freshly upgraded Revo 2.1.1 site. It is not quite working as I expected.

    Here is the code of the resource (the html is mostly taken from the documentation linked above):

    [[!FormIt?
       &hooks=`email`
       &emailSubject=Form email test
       &emailHtml=`1`
       &emailTo=`XXXXXXXX`
       &emailMultiSeparator=`, `
    ]]
    
    <form method="post">
    <label>Color: [[!+fi.error.color]]</label>
    <input type="checkbox" name="color[]" value="blue" [[!+fi.color:FormItIsChecked=`blue`]] > Blue 
    <input type="checkbox" name="color[]" value="red" [[!+fi.color:FormItIsChecked=`red`]] > Red 
    <input type="checkbox" name="color[]" value="green" [[!+fi.color:FormItIsChecked=`green`]] > Green 
    <input type="submit">
    </form>


    The email looks like that (if all checkboxes are checked):

    color: blue
    1: red
    2: green
    color: Array

    Is this expected behavior? Why is the first option labeled color, while the others are numbers? Why is &emailMultiSeparator=`, ` ignored?

    It would be amazing if someone could explain this to me.
      • 24287
      • 14 Posts
      After some more testing more questions arise. I tried to use a template for the email with "&emailTpl=`FormEmailTest`". The rest of the resource is the same as above. The template seems to be interpreted, but the output in the email is weird again. Here is the template code:

      [[+color]]


      And this is the resulting email with all boxes checked:

      , ,

      So finally the EmailMultiSeperator works (as you can see with the commas), but the checked values are missing. Am I doing something wrong, or is the new checkbox feature not fully working yet? It sounds so promising and I would really love to use it.

      Thanks, Amos.
        • 34183
        • 23 Posts
        I’ve been using the fiProcessArrays snippet in this post: http://modxcms.com/forums/index.php?topic=56559.0 and calling [[+color_values]] to output the check box values.
          • 24287
          • 14 Posts
          It’s amazing, and it works! Thank you so much for pointing me there.
            • 34183
            • 23 Posts
            You’re welcome, glad to help.
              • 35143
              • 2 Posts
              FormIt 1.6.0 is supposed to handle this correctly without using a custom snippet AFAIK, but I think something is wrong. If you add

              &emailMultiSeparator=`\n` &emailMultiWrapper=`[[+value]]`


              to the FormIt snippet call, then FormIt behaves as expected.

              If you wanted a nice comma-delimited list instead, than you can use &emailMultiSeparator=`, ` and [[+color]] and it should output "Blue, Red, Green" in the email.

              Don’t forget &emailMultiWrapper=`[[+value]]`. Leaving it out will not produce any output.
                • 24287
                • 14 Posts
                That’s brilliant, thanks.

                You do not happen to know how to remove the [[+color]] in the email if no checkbox is ticked?
                  • 36541
                  • 222 Posts
                  I’ve just come on this issue and that’s what I found with FormIt 1.6 and MODX 2.2-dev (develop from git).

                  1. If no index or numerical index is used on array name
                  <input name="array[]"...
                  <input name"array[]"...
                  or
                  <input name="array[1]"...
                  <input name="array[2]"...
                  values are dumped as
                  array: value0
                  1: value1


                  2. Array fields are overwritten if there are more than one array. For
                  <input name="array1[]"...
                  <input name"array1[]"...
                  
                  <input name="array2[]"...
                  <input name"array2[]"...
                  or
                  <input name="array1[1]"...
                  <input name="array1[2]"...
                  
                  <input name="array2[1]"...
                  <input name="array2[2]"...
                  values are dumped as
                  array1: value0
                  1: value1
                  array2: value0
                  where [tt]value1[/tt] comes from [tt]array2[/tt]!

                  3. This error doesn’t happen for string indexes. For
                  <input name="array[a]"...
                  <input name"array[b]"...
                  values are dumped as
                  array.a: value0
                  array.b: value1

                    This is the web: the only thing you know about who will come is that you don't know who will come.
                    • 36541
                    • 222 Posts
                    Quote from: rabimoe at Jun 14, 2011, 11:06 AM

                    The template seems to be interpreted, but the output in the email is weird again. Here is the template code:

                    [[+color]]


                    And this is the resulting email with all boxes checked:

                    , , 


                    So finally the EmailMultiSeperator works (as you can see with the commas), but the checked values are missing. Am I doing something wrong, or is the new checkbox feature not fully working yet? It sounds so promising and I would really love to use it.

                    The same happens when using FormItRetriever. Any array field is returned empty. The only case in which it showed values for me was when I called FormItRetriever on the form page and on validation error.
                      This is the web: the only thing you know about who will come is that you don't know who will come.