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

    I am trying to set up a simple order form using formIt and getResources. Basically, I have a bunch of 'product' resources, where I add an image, a price, a title etc. The end goal is to display each product within a form, with an input for quantity. So people can bulk order; enter how many of each product they want, and have that sent in an email.

    The product resources are rendered inside a formIt form with getResources. The getResources template has an input for quantity that I need to somehow pass along as a formIt tag to display in the formIt email template.

    Here is my getResources template:
     <tr>
        <td class="product-image">
            [[+tv.product-image]]
        </td>
        <td class="product-title">
    	    [[+pagetitle]]
        </td>
        <td class="product-price">
    	    [[+tv.product-price]]
        </td>
        <td class="product-quantity">
    	    QTY:  <input placeholder="0" name=""  min="0"  type="number" value="" />
        </td>
      </tr>


    And here is my form:
    [[!FormIt?
    	&hooks=`email`
    	&emailTpl=`orderFormTpl`
    	&emailTo=`[email protected]`
    ]] 
    <form action="[[~[[*id]]]]" method="post">
    <table>
    [[!getResources? 
    	&parents=`6` 
    	&tpl=`productTpl`
    	&includeTVs=`1`
    	&processTVs=`1`
    	&sortby=`menuindex`
    	&sortdir=`ASC`
    	&limit=`0`
    ]]
    </table>
    <input class="btn" type="submit" value="Submit" /> 
    </form>

    As far as I can tell, an input needs to have the name match the value in order for it to render in the email. So if
    name="this"
    then value would need to be
    value="[[!+fi.this]]


    But I am at a loss as to how to have the name be pagetitle, and value be pagetitle + user input for quantity, and have that info passed along to the formIt email template.

    So can formIt take this info from dynamically generated inputs and render it in the email? I am leaning towards this not being possible. But I have learned not to underestimate the knowledge of this community!

    Any advice would be greatly appreciated.

    Thanks!
      • 17301
      • 932 Posts
      I would imagine that this may work?

      value="[[!+fi.[[+pagetitle]]]]
        ■ email: [email protected] | ■ website: https://alienbuild.uk

        The greatest compliment you can give back to us, is to spend a few seconds leaving a rating at our trustpilot: https://uk.trustpilot.com/review/alienbuild.uk about the service we provided. We always drop mention of services offered by businesses we've worked with in the past to those of interest.
        • 44165
        • 20 Posts
        No luck. [[!+fi.[[+pagetitle]]]] doesn't render anything... just shows up as value="". Thanks for the suggestion though!
          • 30585
          • 833 Posts
          In your email template, use the names of your input fields as placeholders. And in your getResource listing tpl, make sure you have valid html fields with valid names that match the placeholders used in the email tpl. You can use hidden input fields if you don't want to display those fields to the user.

          You could modify your getResource tpl like this:
          <tr>
             <td class="product-image">
                 [[+tv.product-image]]
             </td>
             <td class="product-title">
                 [[+pagetitle]]
                <input type="hidden" name="productTitle" value="[[+pagetitle]]" />
             </td>
             <td class="product-price">
                 [[+tv.product-price]]
               <input type="hidden" name="productPrice" value="[[+tv.product-price]]" />
             </td>
             <td class="product-quantity">
                 QTY:  <input placeholder="0" name="qty"  min="0"  type="number" value="" />
             </td>
           </tr>


          Then,
          in your email tpl, you can use the following placeholders wherever appropriate:

          [[+productTitle]]
          [[+productPrice]]
          [[+qty]] [ed. note: treigh last edited this post 7 years, 2 months ago.]
            A MODx Fanatic
            • 44165
            • 20 Posts
            Thanks treigh!
            Now we are getting somewhere, that makes a lot of sense. The issue now is this: every product being called in by getResources gets the same placeholders. FormIt is only taking the info from the last resource in the list. If I add multiple sets of placeholders in the email template, then I just get that many of the last resource on the list. Is there a way to have the email template be for each one? So however many resources are on the list, get the unique info for each one? Does that make sense? Right now I have 10 products being called by getResources, and 10 sets of [[+productTitle]] - [[+qty]] in my email template, and I get an email with 10 product - quy of the last product on the list. Like this:
            Product10 - 2
            Product10 - 2
            Product10 - 2
            Product10 - 2
            Product10 - 2
            Product10 - 2
            Product10 - 2
            Product10 - 2
            Product10 - 2
            Product10 - 2

            Thanks!
              • 44165
              • 20 Posts
              Hmmm... Ok, so I was able to get that done using [[+idx]] in my getResources call:
              <tr>
                 <td class="product-image">
                     [[+tv.product-image]]
                 </td>
                 <td class="product-title">
                     [[+pagetitle]]
                    <input type="hidden" name="productTitle[[+idx]]" value="[[+pagetitle]]" />
                 </td>
                 <td class="product-price">
                     [[+tv.product-price]]
                 </td>
                 <td class="product-quantity">
                     QTY:  <input placeholder="0" name="qty[[+idx]]"  min="0"  type="number" value="" />
                 </td>
               </tr>

              But then my mail template has to have a whole bunch of placeholders. One for each product:
              [[+productTitle1]]:[[+qty1]]<br>
              [[+productTitle2]]:[[+qty2]]<br>
              [[+productTitle3]]:[[+qty3]]<br>
              [[+productTitle4]]:[[+qty4]]<br>
              [[+productTitle5]]:[[+qty5]]<br>
              [[+productTitle6]]:[[+qty6]]<br>
              [[+productTitle7]]:[[+qty7]]<br>
              [[+productTitle8]]:[[+qty8]]<br>
              [[+productTitle9]]:[[+qty9]]<br>
              [[+productTitle10]]:[[+qty10]]

              So If I were to add a product, id need to add another placeholder set to the email template. Not that big of a deal, but if anyone has any ideas on a better way to do this, I'm all ears. I guess I could just make the email template with like 100 placeholders. Probably wot ever be more than 100 products...
                • 30585
                • 833 Posts
                Can you post the content of your email tpl here?
                  A MODx Fanatic
                  • 44165
                  • 20 Posts
                  The bare bones email tpl at this point is:
                  <table>
                    <tr>
                      <th>Product</th>
                      <th>Price</th>
                      <th>Quantity</th>
                    </tr>
                   <tr><td>[[+productTitle1]]</td><td>[[+productPrice1]]</td><td>[[+qty1]]</td></tr>
                  <tr><td>[[+productTitle2]]</td><td>[[+productPrice2]]</td><td>[[+qty2]]</td></tr>
                  <tr><td>[[+productTitle3]]</td><td>[[+productPrice3]]</td><td>[[+qty3]]</td></tr>
                  <tr><td>[[+productTitle4]]</td><td>[[+productPrice4]]</td><td>[[+qty4]]</td></tr>
                  <tr><td>[[+productTitle5]]</td><td>[[+productPrice5]]</td><td>[[+qty5]]</td></tr>
                  <tr><td>[[+productTitle6]]</td><td>[[+productPrice6]]</td><td>[[+qty6]]</td></tr>
                  <tr><td>[[+productTitle7]]</td><td>[[+productPrice7]]</td><td>[[+qty7]]</td></tr>
                  <tr><td>[[+productTitle8]]</td><td>[[+productPrice8]]</td><td>[[+qty8]]</td></tr>
                  <tr><td>[[+productTitle9]]</td><td>[[+productPrice9]]</td><td>[[+qty9]]</td></tr>
                  </table>
                  

                  At this point, I need to add an incremented row for each resource that gets called in to the form.