We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 14930
    • 70 Posts
    A spin-off question from http://modxcms.com/forums/index.php/topic,34898.0.html

    I have an eForm (on the left of the page) and a product list (using ditto) on the right, like this:

    <table border=0 width=800>
    	<tr>
    	<td align="left" valign="top">
    successful eform code here
    </td>
    <td>[[Ditto? &parents=`4` &depth=`1` &total=`30` &tpl=`ditto_tpl` &sortDir=`ASC` ]]</p></form></td></tr>
    </table>


    and the ditto template has:
    <input type="checkbox" name="maara[]" value="[+longtitle+]: [+pagetitle+]" eform="[+pagetitle+]::1"/> Choose item and number of items <select name="maara[]" eform="maara"><option value="1">1</option>
    <option value="2">2</option>
    <option value="3">3</option>
    </select>


    The form and the dittoed product list work wonderfully except for one thing: when the user leaves a field blank and gets an error (for example: "Some errors were detected in your form: Invalid verification code.") the checkboxes and dropdown menus in the ditto template go unchecked. The information entered on the form itself stays there. Any idea how to fix this? All ’modules’ are the newest versions available.
      • 33337
      • 3,975 Posts
      what is:
      <select name="maara[]" eform="maara">

      You have already used "maara" on the input filed once. Change the name and see what happens.
        Zaigham R - MODX Professional | Skype | Email | Twitter

        Digging the interwebs for #MODX gems and bringing it to you. modx.link
        • 14930
        • 70 Posts
        Thanks, but that doesn’t help.

        Somehow I think ditto is to blame here, can’t find any errors anywhere, and everything else works like a charm. It just doesn’t remember the checkboxes on the dittoed elements... huh
          • 30223
          • 1,010 Posts
          The problem is that you simply can’t use a ditto call inside an eform template. The ditto call isn’t executed until AFTER eForm is finished. Therefore eForm only sees the Ditto call itself and not the values and form elements it produces.

          "But it works for the rest... " I can hear you say smiley

          That is because the Ditto generated markup is inserted into the document during the next document parser round. Here’s what happens...

          <form id="testForm" action="[~[*id*]~]">
          <input type="text" name="Name" eform="Name::1" />
          [[Ditto.....]]
          <form>


          the document parser finds and runs the eForm snippet. eForm parses the above form and returns it to the document. It will now look like this:
          <form id="testForm" action="[~[*id*]~]">
          <input type="hidden" name="formid" value="testForm" />
          <input type="text" name="Name" class="[+vClass_Name+]" value="[+Name+]" />
          [[Ditto.....]]
          <form>

          eForm is finished and has build up a list of fields and properties from the form. In this case it has only found one field "Name" with the property "required field"

          During the next round the document parser now sees a Ditto call and runs Ditto. Result:
          <form id="testForm" action="[~[*id*]~]">
          <input type="hidden" name="formid" value="testForm" />
          <input type="text" name="Name" class="[+vClass_Name+]" value="[+Name+]" />
          <input type="checkbox" name="maara[]" value="[+longtitle+]: [+pagetitle+]" eform="[+pagetitle+]::1"/> Choose item and number of items 
          <select name="maara[]" eform="maara">
          <option value="1">1</option>
          <option value="2">2</option>
          <option value="3">3</option>
          </select>
          <form>


          All looks good in the browser but sadly this is too late for eForm... eForm is no longer running.

          Hope this clarifies things a bit for you.

          The only way of achieving this is to run ditto inside an event function which is triggered by the eformOnBeforeFormParse event and insert Ditto’s result into the form template. That way eForm can parse Ditto’s output.

          There’s plenty of info here in the forum or in teh wiki on how to use eForms events and there’s also some example in the eForm documentation in assets/snippets/eform/docs/
            • 14930
            • 70 Posts
            Thank you, TobyL, for clearing that up.