We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 46886
    • 1,154 Posts
    Hi, a user wants to control the output of a formit email. &tpl= doesn't seem to be working.

    The default email only has '[[+fields]]' and that sort of dumps everything out. How to have finer control?
      • 46886
      • 1,154 Posts
      Ok I am working on an output modifier for this, I think this should be a string of data provided programmically through the tool.

      So I think this should work

      <p>[[+fields:notempty=`[[+fields]]`]]</p>

      Any thoughts?
        • 46886
        • 1,154 Posts
        This doesn't work apparently
          • 17301
          • 932 Posts
          It would be helpful if you posted what you currently have in your form and formit call so we can see what it is you're trying to output. So long as you have an input with the name fields then that value will be set into the [[+fields]] output.
            ■ 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.
            • 46886
            • 1,154 Posts
            Hey LK thanks, this is still from that long thread, let me give you the relevant pieces.

            All we are trying to do at this point is get the null values stripped out, the modifiers don't work on [[+fields]] but presumably work on the other values that we have, name address and so on, which all output properly. Would perhaps [[+product]] work?

            This is the tpl which has the checkboxes

            <li>
            <p>
            <strong>[[+title]]</strong>
                    [[+description]]
                    [[+price]]
            </p>
             
            <select name="product_[[+title]]">
                    <option value="0">0</option>
                    <option value="1">1</option>
                    <option value="2">2</option>
                    <option value="3">3</option>
            </select>
            </li> 


            and this is the form itself

            <fieldset>    
             
                [[!+fi.validation_error_message:notempty=`<div class="alert alert-error">[[!+fi.validation_error_message]]</div>`]]
                [[!+fi.successMessage]]
             
                <div id="productenlist">
                    <h3><br>Warme Gerechten</h3>
                    <ul>[[getImageList? &tvname=`WarmeGerechten` &tpl=`tLoadlist`]]</ul>
                    <h3><br>Burgers</h3>
                    <ul>[[getImageList? &tvname=`Burgers` &tpl=`tLoadlist`]]</ul>
                    <h3><br>Dranken</h3>
                    <ul>[[getImageList? &tvname=`Dranken` &tpl=`tLoadlist`]]</ul>
                    <h3><br>Warme Broodjes</h3>
                    <ul>[[getImageList? &tvname=`WarmeBroodjes` &tpl=`tLoadlist`]]</ul>
                    <h3><br>KoudeBroodjes</h3>
                    <ul>[[getImageList? &tvname=`KoudeBroodjes` &tpl=`tLoadlist`]]</ul>
                    <h3><br>Salades</h3>
                    <ul>[[getImageList? &tvname=`Salades` &tpl=`tLoadlist`]]</ul>
                    <h3><br>Snacks en Frites</h3>
                    <ul>[[getImageList? &tvname=`SnacksFrites` &tpl=`tLoadlist`]]</ul>
                </div>
                 
                <input type="hidden" name="inputChecker" value="" />
                <input type="hidden" name="contactFormIt" value="1" />
             
                <label for="naam">Name</label>
                <input type="text" id="naam" name="naam" placeholder="full name" title="Enter your name" class="required" value="[[!+fi.naam]]">
                 
                <label for="naam">Company</label>
                <input type="text" id="bedrijf" name="bedrijf" placeholder="company name" title="Enter your name" class="required" value="[[!+fi.bedrijf]]">
                 
                <label for="email">E-mail</label>
                <input type="email" name="email" placeholder="[email protected]" title="Enter your e-mail address" class="required email"  value="[[!+fi.email]]">
             
                <label for="bericht">Message</label>
                <textarea  id="bericht" name="bericht">[[!+fi.bericht]]</textarea>
                <input type="submit" class="button" value="Send Message"> 
            </fieldset>
              • 17301
              • 932 Posts
              Ah ok. Well from what I can tell there is no value being set to [[+fields]] as there is no input with a name of 'fields', unless there is a custom hook in the formit call that is setting that value?

              The problem is that the field names are dynamic so this is why I advised to setup the names with 'product_', so in a hook you can find any values with this prefix, explode them and then dictate their return - someone may be able to advise you on the correct php for this as I assume mine didnt work wink

              Try this - it may not work but if it fails check the error log for guidance or keep tweaking it to get it work smiley I think each time it loops through the value may be replaced though so I think you need to use str replace... hopefully someone can guide you on that.

              <?php
               
              $allValues = $hook->getValues();
              $product = array();
              
              foreach($allValues as $key => $value) {
                  if (strpos($key, 'products_') !== false) {
               
                      $modx->log(xPDO::LOG_LEVEL_ERROR, 'There were values found with the prefix product_');
               
                      list($prefix, $productTitle) = explode('_', $key);
               
                      $modx->log(xPDO::LOG_LEVEL_ERROR,'The products found were:' . $productTitle);
               
                      $productList .= 'Title:' . $product[$key] . 'Quantity' . $product[$value];
               
                      $hook->setValue('products', $productList);
               
                      return true;
               
                  } else{
               
                      $modx->log(xPDO::LOG_LEVEL_ERROR, 'There were no values matching product_');
               
                      return false;
               
                  }
              }
              


              Then set [[+products]] in your emailtpl.

              As a get around the other thing you may be able to do is in your emailTpl recall all the titles using the getImageList snippet. Remove the product_ prefix from your chunk first though.

              [[getImageList? &tvname=`WarmeGerechten` &tpl=`@CODE:<p>Product: [[+property.tvname]] Quantity: [[+title]]</p>`]]
              [[getImageList? &tvname=`Burgers` &tpl=`@CODE:<p>Product: [[+property.tvname]] Quantity: [[+title]]</p>`]]
              [[getImageList? &tvname=`Dranken` &tpl=`@CODE:<p>Product: [[+property.tvname]] Quantity: [[+title]]</p>`]]
              ...

              [ed. note: lkfranklin last edited this post 5 years, 7 months ago.]
                ■ 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.
                • 17301
                • 932 Posts
                Also I'm just going to plug formalicious here from modmore:
                https://www.modmore.com/formalicious/?via=1346
                  ■ 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.
                  • 46886
                  • 1,154 Posts
                  Thanks LK this is great, I have learned a lot through this process from you. Its interesting to see a system revealed in this way. I didn't realize how it would work and was concerned about getting into the php without being sure it would solve the problem.

                  Ok so these are two possible solutions, and the second one does not require the custom php, is that right?

                  So the second one probably should be tried first as that's just changing the email tpl which we have done many times.

                  For the snippet, its going to be a hook right, presumably before the email hook but it may not matter...
                    • 38783
                    • 571 Posts
                    I think what you need to do this is already built into Formit with FormitAutoResponder (&fiar) and FormItSaveForm (&store). Or I have misunderstood the question - which is quite possible!

                    Formit call
                    [[!FormIt?
                       &hooks=`spam,FormItSaveForm,email,FormItAutoResponder,redirect`
                       &emailSubject=`RCDTBP Contact [[+firstname]] [[+lastname]]`
                       &emailTpl=`EmailSent`
                       &emailTo=`[email protected]`
                       &store=`1`
                       &redirectTo=`77`
                       &validate=`firstname:required,
                       lastname:required,
                       email:email:required,
                       tel:required,
                       nospam:blank`
                       &fiarTpl=`emailResponseContactForm`
                      &fiarSubject=`My Website Contact Form`
                      &fiarToField=`email`
                      &fiarFrom=`[email protected]`
                      &fiarReplyTo=`[email protected]`
                      &fiarReplyToName=`Custom Name`
                    
                    
                    


                    emailResponseContactForm template
                    Hello [[!+firstname]] [[!+lastname]]
                    Some more text and custom fields.....
                    

                    Where first name and last name are custom fields in your form [ed. note: andytough last edited this post 5 years, 7 months ago.]
                      If I help you out on these forums I would be very grateful if you would consider rating me on Trustpilot: https://uk.trustpilot.com/review/andytough.com

                      email: [email protected] | website: https://andytough.com
                      • 54524
                      • 34 Posts
                      LK:
                      The first solution isn't working. But I think it might is in the hook instead of the php. The email isn't sending or saving when I use the hook:
                      &hooks=`processOrder,spam,email,FormItSaveForm`


                      The second solution: I changed it a bit and now I'm able to receive the first value (first product in the list of many products)!
                      I use this:
                      [[getImageList? &tvname=`WarmeGerechten` &tpl=`@CODE:<p>Product: [[+property.tvname]][[+title]] Quantity: [[+amount[[+MIGX_id]]]]</p>`]] 

                      The other values are in the list but stay at zero.

                      So the next question will be: how can we process all the values instead of only one item?

                      Feels like we're close to the soluction!:)