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

    I am using EVO 1.06 and using Ditto to populate a multiple select box in an eForm form.

    To get the multiple select working with eForm, I believe I have to include a sequential number for each "option" within each "optgroup". Eg:
    <option name="prod01" value="Product Name">Product Name</option>
    <option name="prod02" value="Product Name">Product Name</option>
    <option name="prod03" value="Product Name">Product Name</option>
    etc

    Does anyone know any tricks to include a sequential number in a ditto template?

    Or is there another way to get the multiple select box working in an eForm form?

    4 Ditto Calls for 4 different categories:
    <optgroup label="Products 1">
    [[Ditto? id=`id174` &startID=`174` &depth=`0` &hideFolders=`1` &tpl=`efs-menu-row` &noResults=`efs-menu-NO` &orderBy=`pagetitle ASC`]]
    </optgroup>
    <optgroup label="Products 2">
    [[Ditto? id=`id129` &startID=`129` &depth=`0` &hideFolders=`1` &tpl=`efs-menu-row` &noResults=`efs-menu-NO` &orderBy=`pagetitle ASC`]]
    </optgroup>
    <optgroup label="Products 3">
    [[Ditto? id=`id143` &startID=`143` &depth=`0` &hideFolders=`1` &tpl=`efs-menu-row` &noResults=`efs-menu-NO` &orderBy=`pagetitle ASC`]]
    </optgroup>
    <optgroup label="Products 4">
    [[Ditto? id=`id181` &startID=`181` &depth=`0` &hideFolders=`1` &tpl=`efs-menu-row` &noResults=`efs-menu-NO` &orderBy=`pagetitle ASC`]]
    </optgroup>

    Current Ditto template:
    <option name="prod" value="[+pagetitle+]">[+pagetitle+]</option>


    Any ideas?


    I tested the code below by manually inserting it into the eForm call and it works fine so I believe the sequential number from Ditto will work:
    <div class="formrow">
     <label for="Product-Project" >Test</label>
     <select name="prod[]" multiple="multiple">
       <optgroup label="Products 1">
        <option name="prod01" value="Product A">Product A</option>
        <option name="prod02" value="Product B">Product B</option>
        <option name="prod03" value="Product C">Product C</option>
        <option name="prod04" value="Product D">Product D</option>
       </optgroup>
       <optgroup label="Products 2">
        <option name="prod01" value="Product E">Product E</option>
        <option name="prod02" value="Product F">Product F</option>
        <option name="prod03" value="Product G">Product G</option>
        <option name="prod04" value="Product H">Product H</option>
       </optgroup>
       <optgroup label="Products 3">
        <option name="prod01" value="Product I">Product I</option>
        <option name="prod02" value="Product J">Product J</option>
       </optgroup>
       <optgroup label="Products 4">
        <option name="prod01" value="Product K">Product K</option>
        <option name="prod02" value="Product L">Product N</option>
        <option name="prod03" value="Product M">Product M</option>
       </optgroup>
     </select>
    </div>


    Thanks in advance.
      Web design Adelaide
      http://gocreate.com.au
      • 19369
      • 1,098 Posts
      This is untested, let me know if it works.
      <option name="prod0[+ditto_iteration+]" value="[+pagetitle+]">[+pagetitle+]</option>


      Documentation:
      http://wiki.modxcms.com/index.php/Ditto_2.1_placeholders#General_placeholders

      Related Threads:
      http://forums.modx.com/index.php?topic=45883.0
      http://forums.modx.com/index.php?topic=43917.0
      http://forums.modx.com/thread/42617/ditto-numeric-sequence-and-number-of-documents#dis-post-246589 -> If you want to start from 1 and not from 0.
        • 21417
        • 486 Posts
        Thanks microcipcip.

        That gives me the number, but breaks when more than 10.

        Eg

        name="prod01"
        name="prod02"
        ...
        name="prod09"
        name="prod010"
        name="prod011"
        name="prod012"
        ...

        With or without zero does not work with eForm:
        <option name="prod0[+ditto_iteration:math=`?+1`+]"...>
        <option name="prod[+ditto_iteration:math=`?+1`+]"...>


        Any ideas?
        [ed. note: nickf08 last edited this post 11 years, 11 months ago.]
          Web design Adelaide
          http://gocreate.com.au
          • 19369
          • 1,098 Posts
          Maybe you can test if it is greater than 10 with http://wiki.modxcms.com/index.php/PHx#eg or with http://wiki.modxcms.com/index.php/PHx#math.3D.60calculation.60 , and output the 0 with an if/else inside the ditto_iteration.
            • 21417
            • 486 Posts
            great idea!

            <option name="prod[+phx:if=`[+ditto_iteration+]`:lt=`9`:then=`0`:else=``+][+ditto_iteration:math=`?+1`+]" value="[+pagetitle+]">[+pagetitle+]</option>


            This gives me the right set of numbers which is awesome....

            Eg
            name="prod01"
            name="prod02"
            ...
            name="prod09"
            name="prod10"
            name="prod11"
            name="prod12"

            ... but eForm says:
            Some errors were detected in your form:
            pro » Incorrect value

            Any ideas of where I went wrong?
            [ed. note: nickf08 last edited this post 11 years, 11 months ago.]
              Web design Adelaide
              http://gocreate.com.au
              • 21417
              • 486 Posts
              Thanks for your help micorcipcip.

              I could not get eForm to work with select boxes - so I changed to checkboxes instead.
                Web design Adelaide
                http://gocreate.com.au
                • 19369
                • 1,098 Posts
                Is there a reason to have them in a specific order?
                Edit: sorry I thought it was a normal "select", not a multiselect. [ed. note: microcipcip last edited this post 11 years, 11 months ago.]
                  • 21417
                  • 486 Posts
                  No, not at all - I just couldn't get it to work without a sequential number in the name in my manual tests (eg without using ditto) so I thought it was required.

                  I tried with doc id for example but that did not work - it only seemed to work for me with the sequential number in manual testing.

                  The ditto iteration trick worked a treat - I just did not have any success sending with eform.

                  No problems anyway, as I have changed to scrollable checkboxes, probably more useable anyway.

                  Thanks again

                    Web design Adelaide
                    http://gocreate.com.au