We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 5894
    • 10 Posts
    Im using a snippet Ive written called ’PlacementCheckboxes’ to do database queries that result in the checkboxes for a form.

    The form is in the chunk ’MyForm’ and Im calling the snippet to output the checkboxes at the correect place using [[PlacementCheckboxes]] within the chunk.

    This works fine. I know the chunks dont parse php but calling the snippet within the chunk works fine.

    Heres where Im stuck:

    I have another chunk called ’MyForm_report’ which creates the email report.

    In just the same way as above I have a snippet in there called [[PlacementCheckboxes_report]] which does the DB queries to pull out the current set of form options in order to generate the report email. But in this Chunk the snippet doesnt work. It just outputs the text "Placement Options: [[PlacementCheckboxes_report]]" within the email.

    So what am I missing? eForm appears happy to use the snippet in the Form generation chunk, but wont parse the snippet in the report email chunk.

    Id really appreciate some pointers.

    Thanks.

      • 30223
      • 1,010 Posts
      So what am I missing? eForm appears happy to use the snippet in the Form generation chunk, but wont parse the snippet in the report email chunk.

      In fact there’s no happiness at all here and it’s not eForm which is using either snippet. This is starting to become a common misunderstanding. EForm template chunks are only ever parsed for place holders that eForm can recognize, which currently are [+placeHolder+] tags for which the values are either come from the submitted form, the language files or from eForm events.

      Embedded snippet calls or chunks in template chunks are left alone by eForm. That they appear "to work" is simply because the MODx document parser works recursively and will, once eForm is finished, re-parse the resulting content for more chunks, snippets etcetera. So what you see in your browser is the result of MODx replacing your embedded snippets/chunks and not eForm. This recursive parsing after eForm only happens with "normal" documents, when things are output to the browser. With the email report chunk which doesn’t result directly in browser output (but instead creates the body of an email) this recursive parsing doesn’t happen and hence embedded snippets do not get called!

      An example:

      Suppose a form template like this:

      <form id="myID">
         <label>My Name</label>
         <input type="text" name="myName" eform="Your Name::1:We need the correct name:#VALUE John Doe" />
         <label>My Select</label>
         <select name="mySelect"
         [[myDynamicSelect? &min=`1` &max=`4`]]
         </select>
      </form>


      And a document like this

      <h3>Special Form<h3>
       <p>Please fill in the form below, blah blah...</p>
       [!eForm? &tpl=`myFormTemplate` &formid=`myID`!]



      Step 1. MODx parses the document and finds and runs the eForm snippet.
      Step 2. Eform loads and parses the form template. Once finished it returns the result to MODx. The result would look like this:

      <h3>Special Form<h3>
       <p>Please fill in the form below, blah blah...</p>
      <form id="myID">
         <label>My Name</label>
         <input type="text" name="myName" />
         <label>My Select</label>
         <select name="mySelect"
         [[myDynamicSelect? &min=`1` &max=`4`]]
         </select>
      </form>


      Step 3.
      MODx parses the (resulting) document again and finds and runs the myDynamicSelect snippet.
      Step 4. myDynamicSelect runs it’s code and returns the result to MODx. The result will now look like:

      <h3>Special Form<h3>
       <p>Please fill in the form below, blah blah...</p>
      <form id="myID">
         <label>My Name</label>
         <input type="text" name="myName" />
         <label>My Select</label>
         <select name="mySelect"
            <option vaue="1">One</option>
            <option vaue="2">One</option>
            <option vaue="3">One</option>
            <option vaue="4">One</option>
         </select>
      </form>


      Step 5. Document is send to the browser (after a bit more processing).

      Step 6. You get the idea that all is hunky dory. Sadly this is not true. eForm as you can deduct from the above has no idea about the four <option> values as they were not in the form yet by the time eForm was run.

      Step 7. The form is submitted with correct value, and the whole process starts again at step 1, except this time eForm parses the report template (at step 3) and sends the email, then discards the resulting report and returns to MODx with a "thank you" message (or something similar) Step 4 is never executed while the report template is active!

      Sorry for the drawn out explanation but I hope this clarifies things a bit for you. To achieve what you want you’ll need to use eForm’s events. For some examples have a look in the documentation and browse through these forums...
        • 5894
        • 10 Posts
        Thanks so much for the explanation. That is really helpful and does clear things up.

        Explanations like that should be added to the wiki as it must be a common confusion.

        So I’ll use eForms event’s for both initial form generation and the email. I suspected there was some huge gap in my understanding that was to blame... and there was smiley

        Cheers