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

    I have a requirement for some assistance as below:

    I have a dynamic form that is created from a WayFinder call to pull data from a set of resources in a specified container. This allows the content of the form to be dynamic and change as per the content which the website needs to display.

    With a dynamically generated form, I need a dynamically generated emailTpl to send the contents of the form to an email address. I can't seem to work out how to get the values of the form into an emailTpl as the emailTpl seems to want to use hard-coded code to reference.

    How can I create the emailTpl dynamically, including a reference to all the form field elements in the dynamically generated formit form?

    I think a Post Hook is what I need - but I have no idea on how to create such a PHP solution to get it to work...

    Some related reading here > https://forums.modx.com/thread/99203/formit-and-wayfinder

    Appreciate any assistance anyone can offer here.

    Cheers,


    dubbs.

    This question has been answered by dubbs. See the first response.

      • 4172
      • 5,888 Posts
      can't you generate the output for the tpl in a hook and set it into a new value, which you then use as a placeholder in the emailTpl.

      Also running snippets in an emailTpl is possible.
        -------------------------------

        you can buy me a beer, if you like MIGX

        http://webcmsolutions.de/migx.html

        Thanks!
        • 8168
        • 1,118 Posts
        Quote from: Bruno17 at Jan 06, 2016, 08:05 AM
        can't you generate the output for the tpl in a hook and set it into a new value, which you then use as a placeholder in the emailTpl.

        Also running snippets in an emailTpl is possible.

        Thanks Bruno - do you have an example you can share?
          • 8168
          • 1,118 Posts
          Note - I can format the tpl to include the relevant elements from the wayfinder call - what I am missing is the 'filled out' data from the dynamic form...
            • 4172
            • 5,888 Posts
            can you post an example, when you fill a form, what you get with a hook - snippet like that:

            $values = $hook->getValues();
            
            echo '<pre>' . print_r($values,1) . '</pre>';
            die();  


            and the output, which you want to get in the email?
              -------------------------------

              you can buy me a beer, if you like MIGX

              http://webcmsolutions.de/migx.html

              Thanks!
              • 28042 ☆ A M B ☆
              • 24,524 Posts
              If I understand correctly, dubbs wants the field names, and thus the placeholder keys, to be variable. The email tpl is not processed by MODX, so you can't make those variable.

              I was thinking of using a post-hook to actually create the chunk content, saving it to the database, so that when the email hook fetches it to use for the email tpl it will have the appropriate placeholder keys.

              If FormIt can take an inline tpl for the emailTpl, then it should be possible to just write that in a post-hook, but I haven't been able to determine if that is the case.
                Studying MODX in the desert - http://sottwell.com
                Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
                Join the Slack Community - http://modx.org
                • 8168
                • 1,118 Posts
                Hi Bruno,

                Formit call:

                [[!FormIt?
                   &hooks=`FormItSaveForm,email,redirect`
                   &emailSubject=`Test order form submission`
                   &emailTo=`[email protected]`
                   &redirectTo=`43`
                   &store=`1`
                   &fsFormTopic=`Order Form`
                &emailTpl=`productTPL-Email2`
                ]]
                


                So the form is created with a wayfinder call as below:

                <table width="100%" border="1">
                <tr>
                <th> </th>
                <th>Mon</th>
                <th>Tue</th>
                <th>Wed</th>
                <th>Thur</th>
                <th>Fri</th>
                <th>Sat</th>
                <th>Sun</th>
                </tr>
                [[Wayfinder? &startId=`32`&level=`3` &rowTpl=`productTPL` &parentRowTpl=`sectionTPL` &outerTpl=`wrapperTPL2`]]
                </table>
                


                sectionTPL:

                <tr><th colspan="8" style="text-align:left;">[[+wf.linktext]]</th></tr>
                [[+wf.wrapper]]
                


                productTpl:

                <tr><td>[[+wf.linktext]][[+wf.wrapper]]</td>
                
                <td><select name="[[+wf.title]]_Mon" id="[[+wf.title]]_Mon" value="[[!+wf.title]]]">
                <option>0</option>
                <option value="1" [[!+wf.title_Mon:FormItIsSelected=`1`]]>1</option>
                <option value="2" [[!+wf.title_Mon:FormItIsSelected=`2`]]>2</option>
                <option value="3" [[!+wf.title_Mon:FormItIsSelected=`3`]]>3</option>
                <option value="4" [[!+wf.title_Mon:FormItIsSelected=`4`]]>4</option>
                <option value="5" [[!+wf.title_Mon:FormItIsSelected=`5`]]>5</option>
                <option value="6" [[!+wf.title_Mon:FormItIsSelected=`6`]]>6</option>
                <option value="7" [[!+wf.title_Mon:FormItIsSelected=`7`]]>7</option>
                <option value="8" [[!+wf.title_Mon:FormItIsSelected=`8`]]>8</option>
                <option value="9" [[!+wf.title_Mon:FormItIsSelected=`9`]]>9</option>
                </select></td>
                
                <td><select name="[[+wf.title]]_Tue" id="[[+wf.title]]_Tue">
                <option>0</option>
                <option value="1" [[!+wf.title_Tue:FormItIsSelected=`1`]]>1</option>
                <option value="2" [[!+wf.title_Tue:FormItIsSelected=`2`]]>2</option>
                <option value="3" [[!+wf.title_Tue:FormItIsSelected=`3`]]>3</option>
                <option value="4" [[!+wf.title_Tue:FormItIsSelected=`4`]]>4</option>
                <option value="5" [[!+wf.title_Tue:FormItIsSelected=`5`]]>5</option>
                <option value="6" [[!+wf.title_Tue:FormItIsSelected=`6`]]>6</option>
                <option value="7" [[!+wf.title_Tue:FormItIsSelected=`7`]]>7</option>
                <option value="8" [[!+wf.title_Tue:FormItIsSelected=`8`]]>8</option>
                <option value="9" [[!+wf.title_Tue:FormItIsSelected=`9`]]>9</option>
                </select></td>
                
                <td><select name="[[+wf.title]]_Wed" id="[[+wf.title]]_Wed">
                <option>0</option>
                <option value="1" [[!+wf.title_Wed:FormItIsSelected=`1`]]>1</option>
                <option value="2" [[!+wf.title_Wed:FormItIsSelected=`2`]]>2</option>
                <option value="3" [[!+wf.title_Wed:FormItIsSelected=`3`]]>3</option>
                <option value="4" [[!+wf.title_Wed:FormItIsSelected=`4`]]>4</option>
                <option value="5" [[!+wf.title_Wed:FormItIsSelected=`5`]]>5</option>
                <option value="6" [[!+wf.title_Wed:FormItIsSelected=`6`]]>6</option>
                <option value="7" [[!+wf.title_Wed:FormItIsSelected=`7`]]>7</option>
                <option value="8" [[!+wf.title_Wed:FormItIsSelected=`8`]]>8</option>
                <option value="9" [[!+wf.title_Wed:FormItIsSelected=`9`]]>9</option>
                </select></td>
                
                <td><select name="[[+wf.title]]_Thur" id="[[+wf.title]]_Thur">
                <option>0</option>
                <option value="1" [[!+wf.title_Thur:FormItIsSelected=`1`]]>1</option>
                <option value="2" [[!+wf.title_Thur:FormItIsSelected=`2`]]>2</option>
                <option value="3" [[!+wf.title_Thur:FormItIsSelected=`3`]]>3</option>
                <option value="4" [[!+wf.title_Thur:FormItIsSelected=`4`]]>4</option>
                <option value="5" [[!+wf.title_Thur:FormItIsSelected=`5`]]>5</option>
                <option value="6" [[!+wf.title_Thur:FormItIsSelected=`6`]]>6</option>
                <option value="7" [[!+wf.title_Thur:FormItIsSelected=`7`]]>7</option>
                <option value="8" [[!+wf.title_Thur:FormItIsSelected=`8`]]>8</option>
                <option value="9" [[!+wf.title_Thur:FormItIsSelected=`9`]]>9</option>
                </select></td>
                
                <td><select name="[[+wf.title]]_Fri" id="[[+wf.title]]_Fri">
                <option>0</option>
                <option value="1" [[!+wf.title_Fri:FormItIsSelected=`1`]]>1</option>
                <option value="2" [[!+wf.title_Fri:FormItIsSelected=`2`]]>2</option>
                <option value="3" [[!+wf.title_Fri:FormItIsSelected=`3`]]>3</option>
                <option value="4" [[!+wf.title_Fri:FormItIsSelected=`4`]]>4</option>
                <option value="5" [[!+wf.title_Fri:FormItIsSelected=`5`]]>5</option>
                <option value="6" [[!+wf.title_Fri:FormItIsSelected=`6`]]>6</option>
                <option value="7" [[!+wf.title_Fri:FormItIsSelected=`7`]]>7</option>
                <option value="8" [[!+wf.title_Fri:FormItIsSelected=`8`]]>8</option>
                <option value="9" [[!+wf.title_Fri:FormItIsSelected=`9`]]>9</option>
                </select></td>
                
                <td><select name="[[+wf.title]]_Sat" id="[[+wf.title]]_Sat">
                <option>0</option>
                <option value="1" [[!+wf.title_Sat:FormItIsSelected=`1`]]>1</option>
                <option value="2" [[!+wf.title_Sat:FormItIsSelected=`2`]]>2</option>
                <option value="3" [[!+wf.title_Sat:FormItIsSelected=`3`]]>3</option>
                <option value="4" [[!+wf.title_Sat:FormItIsSelected=`4`]]>4</option>
                <option value="5" [[!+wf.title_Sat:FormItIsSelected=`5`]]>5</option>
                <option value="6" [[!+wf.title_Sat:FormItIsSelected=`6`]]>6</option>
                <option value="7" [[!+wf.title_Sat:FormItIsSelected=`7`]]>7</option>
                <option value="8" [[!+wf.title_Sat:FormItIsSelected=`8`]]>8</option>
                <option value="9" [[!+wf.title_Sat:FormItIsSelected=`9`]]>9</option>
                </select></td>
                
                <td><select name="[[+wf.title]]_Sun" id="[[+wf.title]]_Sun">
                <option>0</option>
                <option value="1" [[!+wf.title_Sun:FormItIsSelected=`1`]]>1</option>
                <option value="2" [[!+wf.title_Sun:FormItIsSelected=`2`]]>2</option>
                <option value="3" [[!+wf.title_Sun:FormItIsSelected=`3`]]>3</option>
                <option value="4" [[!+wf.title_Sun:FormItIsSelected=`4`]]>4</option>
                <option value="5" [[!+wf.title_Sun:FormItIsSelected=`5`]]>5</option>
                <option value="6" [[!+wf.title_Sun:FormItIsSelected=`6`]]>6</option>
                <option value="7" [[!+wf.title_Sun:FormItIsSelected=`7`]]>7</option>
                <option value="8" [[!+wf.title_Sun:FormItIsSelected=`8`]]>8</option>
                <option value="9" [[!+wf.title_Sun:FormItIsSelected=`9`]]>9</option>
                </select></td>
                
                </tr>
                


                wrapperTPL2:

                [[+wf.wrapper]]
                


                That all generates a table within the formit form which is great - allowing the user to select the number of each product to order on each day.


                Then looking at the emailTpl that formit uses to send the data (or not as the case is!)

                productTPL-Email2:
                <table width="100%" border="1">
                <tr>
                <th> </th>
                <th>Mon</th>
                <th>Tue</th>
                <th>Wed</th>
                <th>Thur</th>
                <th>Fri</th>
                <th>Sat</th>
                <th>Sun</th>
                </tr>
                [[Wayfinder? &startId=`32`&level=`3` &rowTpl=`productTPL-Output` &parentRowTpl=`sectionTPL` &outerTpl=`wrapperTPL2`]]
                </table>
                


                productTPL-Output:
                <tr><td>[[+wf.linktext]][[+wf.wrapper]]</td>
                
                <td><p>[[+wf.title]]_Mon</p></td>
                <td><p>[[+wf.title]]_Tue</p></td>
                <td><p>[[+wf.title]]_Wed</p></td>
                <td><p>[[+wf.title]]_Thur</p></td>
                <td><p>[[+wf.title]]_Fri</p></td>
                <td><p>[[+wf.title]]_Sat</p></td>
                <td><p>[[+wf.title]]_Sun</p></td>
                
                </tr>
                


                What I see in the email that I get, is not as I want... e.g. I am looking to see:

                          Mon       Tue      Wed      Thur       Fir       Sat       Sun
                Chicken   10        0        1         5          0         0         0   
                


                What I instead see is:

                          Mon       Tue      Wed      Thur       Fir       Sat       Sun
                Chicken      Chicken_Mon     Chicken_Tue     Chicken_Wed      Chicken_Thur       Chicken_Fri      Chicken_Sat      Chicken_Sun
                


                So the values set in the formit form for Chicken_Mon etc are not making it into the email tpl and therefore not sent in the email received on submit of the form.... All I get where the values (e.g. 10, 3, 1 etc) should be is the productname_day data - I must not be calling in the formit stored value of Chicken_Mon correctly....?? How do i do that?


                Hope that all makes sense? [ed. note: dubbs last edited this post 10 years, 9 months ago.]
                  • 8168
                  • 1,118 Posts
                  Quote from: Bruno17 at Jan 06, 2016, 08:36 AM
                  can you post an example, when you fill a form, what you get with a hook - snippet like that:

                  $values = $hook->getValues();
                  
                  echo '<pre>' . print_r($values,1) . '</pre>';
                  die();  


                  and the output, which you want to get in the email?

                  Thanks Bruno - just posted how I am trying to do things... What I am missing is the code in the EmailTpl to pull the value of the dynamic fields...
                    • 8168
                    • 1,118 Posts
                    Quote from: sottwell at Jan 06, 2016, 08:53 AM
                    If I understand correctly, dubbs wants the field names, and thus the placeholder keys, to be variable. The email tpl is not processed by MODX, so you can't make those variable.

                    I was thinking of using a post-hook to actually create the chunk content, saving it to the database, so that when the email hook fetches it to use for the email tpl it will have the appropriate placeholder keys.

                    If FormIt can take an inline tpl for the emailTpl, then it should be possible to just write that in a post-hook, but I haven't been able to determine if that is the case.

                    Susan - Yep, I think you are on the same page as me - please see my code examples for how I am trying to achieve this... In essence it all works, apart from being able to place the formit field values from the formit form to the emailTpl...
                      • 4172
                      • 5,888 Posts
                      I'm sure, you can set values in hooks, which can be used as placeholders in the email-tpl and if I'm not wrong I had also used snippets in email-tpls.

                      But I can't help, if don't want to show us the output of my little hook-snippet above.
                      Should you take 5 minutes to create the snippet, add it as a hook to your formit-call, send the form and post the result here.
                        -------------------------------

                        you can buy me a beer, if you like MIGX

                        http://webcmsolutions.de/migx.html

                        Thanks!