We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 10076
    • 1,024 Posts
    Hi I m trying to build an order form using Migx, client want his visitors to order some weeks ahead. Migx part is finished and renders a form on the page. But I can t figure out how to get the filled in data to be send to the client. Below a form where week numbers are displayed behind a product for the comming next four weeks. each week with a field for the desired weight. How would I get this data in my email chunk? I can t even get the productname in the emailchunk? Let alone the weeknumber with desired weight per product.

    Here the tpl used by migx

    <fieldset>
        <div class="pur_col1 purlineitem"><img src="[[+image:add_before=`assets/images/`:phpthumbof=`w=100&h=100&zc=1]]" alt="Foto van [[+productname]] " ></div>
        <div class="pur_col2 purlineitem"><label for="[[+productname]]"><h4>[[+productname]]:</h4><span class="error">[[!+fi.error.[[+productname]]]]</span></label><input type="hidden" name="[[+productname]]" id="[[+productname]]" value="[[+productname]]"/></div>
        <div class="pur_col4 purlineitem"><label for="[[!getDate:date=`%W`? &offset=`1 Weeks`]]">Week [[!getDate:date=`%W`? &offset=`1 Weeks`]]:<span class="error">[[!+fi.error.[[!getDate:date=`%W`? &offset=`1 Weeks`]]]]</span></label><input type="text" name="[[!getDate:date=`%W`? &offset=`1 Weeks`]]" id="[[!getDate:date=`%W`? &offset=`1 Weeks`]]" placeholder='Gewicht' value="[[!+fi.[[!getDate:date=`%W`? &offset=`1 Weeks`]]]]" /></div>
        <div class="pur_col4 purlineitem"><label for="[[!getDate:date=`%W`? &offset=`2 Weeks`]]">Week [[!getDate:date=`%W`? &offset=`2 Weeks`]]:<span class="error">[[!+fi.error.[[!getDate:date=`%W`? &offset=`2 Weeks`]]]]</span></label><input type="text" name="[[!getDate:date=`%W`? &offset=`2 Weeks`]]" id="[[!getDate:date=`%W`? &offset=`2 Weeks`]]" placeholder='Gewicht' value="[[!+fi.[[!getDate:date=`%W`? &offset=`2 Weeks`]]]]" /></div>
        <div class="pur_col4 purlineitem"><label for="[[!getDate:date=`%W`? &offset=`3 Weeks`]]">Week [[!getDate:date=`%W`? &offset=`3 Weeks`]]:<span class="error">[[!+fi.error.[[!getDate:date=`%W`? &offset=`3 Weeks`]]]]</span></label><input type="text" name="[[!getDate:date=`%W`? &offset=`3 Weeks`]]" id="[[!getDate:date=`%W`? &offset=`3 Weeks`]]" placeholder='Gewicht' value="[[!+fi.[[!getDate:date=`%W`? &offset=`3 Weeks`]]]]" /></div>
        <div class="pur_col4 purlineitem"><label for="[[!getDate:date=`%W`? &offset=`4 Weeks`]]">Week [[!getDate:date=`%W`? &offset=`4 Weeks`]]:<span class="error">[[!+fi.error.[[!getDate:date=`%W`? &offset=`4 Weeks`]]]]</span></label><input type="text" name="[[!getDate:date=`%W`? &offset=`4 Weeks`]]" id="[[!getDate:date=`%W`? &offset=`4 Weeks`]]" placeholder='Gewicht' value="[[!+fi.[[!getDate:date=`%W`? &offset=`4 Weeks`]]]]" /></div>
        <div class="pur_col4 purlineitem"><label for="[[!getDate:date=`%W`? &offset=`5 Weeks`]]">Week [[!getDate:date=`%W`? &offset=`5 Weeks`]]:<span class="error">[[!+fi.error.[[!getDate:date=`%W`? &offset=`5 Weeks`]]]]</span></label><input type="text" name="[[!getDate:date=`%W`? &offset=`5 Weeks`]]" id="[[!getDate:date=`%W`? &offset=`5 Weeks`]]" placeholder='Gewicht' value="[[!+fi.[[!getDate:date=`%W`? &offset=`5 Weeks`]]]]" /></div>
    </fieldset>


    The tpl used to send the data over

    [[+name]] Heeft een bestelling gestuurd: <br />
    <strong>[[+productname]]</strong><br />
    You can respond to [[+name]] by email at <a href="mailto:[[+email]]">[[+email]]</a> etc etc.../code]
      • 4172
      • 5,888 Posts
      You say, you are using getImageList to build the form.

      Are there multiple products listed in the form?

      Then you will need to build the email - output with getImageList, too
      And the weeks - inputs would need to have unique names for each product.
        -------------------------------

        you can buy me a beer, if you like MIGX

        http://webcmsolutions.de/migx.html

        Thanks!
        • 10076
        • 1,024 Posts
        HI Bruno,

        since using Mark Hamstra s instruction for building output, I use that same snippet for al kind of Migx solutions so far.

        here s that "orderform" snippet
        <?php
        $input = $modx->fromJSON($input);
        $output = array();
        if (!$input || empty($tpl)) return ' ';
        foreach ($input as $row) {
          if (isset($set) && !empty($set) && ($set != $row['set'])) continue;
          $output[] = $modx->getChunk($tpl, $row);
        }
        return implode("\n", $output);


        One thing as for my question, in the call to create the email output, how does it pickup it s values. As it s not using an input tv, right?

        Would that call be something like this? Can t be right because of the input var. Not sure how to do this.

         [[orderform? &tpl=`orderTpl` &set=`[[+set]]`]]


        orderTpl, realy lost here,

            <div class="pur_col2 purlineitem"><label for="[[+productname]]"><h4>[[+productname]]:</h4><span class="error">[[!+fi.error.[[+productname]]]]</span></label><input type="hidden" name="[[!getDate:date=`%W`? &offset=`2 Weeks`]][[+productname]][[+productname]]" id="[[+productname]][[+weight]]" value="[[!getDate:date=`%W`? &offset=`1 Weeks`]][[+productname]][[+weight]]"/></div>
            <div class="pur_col2 purlineitem"><label for="[[+productname]]"><h4>[[+productname]]:</h4><span class="error">[[!+fi.error.[[+productname]]]]</span></label><input type="hidden" name="[[!getDate:date=`%W`? &offset=`2 Weeks`]][[+productname]][[+productname]]" id="[[+productname]][[+weight]]" value="[[!getDate:date=`%W`? &offset=`2 Weeks`]][[+productname]][[+weight]]"/></div>


        Hope you can help.
          • 4172
          • 5,888 Posts
          how do you call that snippet in your form?
            -------------------------------

            you can buy me a beer, if you like MIGX

            http://webcmsolutions.de/migx.html

            Thanks!
            • 10076
            • 1,024 Posts
            To build the webform (http://oudwijker.nl/bestel.html),
            [[orderform? &tpl=`orderFormTpl` &input=`[[*product]]` &set=`[[+set]]`]]
            . Just one item created so far.

            To build the email output, I m puzzled.
              • 4172
              • 5,888 Posts
              you can use a hook-snippet to build the products-output.

              I think, you can get the products within your hook-snippet with:

              $input = $modx->fromJson($modx->resource->getTVValue('product'));


              then you can loop thrue the products, build the mail-output and set the result into a placeholder for your email-chunk with:

              $hook->setValue('products_output',$products_output);


              In your mail-chunk, you can use it then with:

              [[+products_output]]


                -------------------------------

                you can buy me a beer, if you like MIGX

                http://webcmsolutions.de/migx.html

                Thanks!
                • 10076
                • 1,024 Posts
                Ehh, something like this?
                my hook snippet "orderInput"
                <?php
                $input = $modx->fromJson($modx->resource->getTVValue('productname'));
                 $hook->setValue('products_output',$products_output);
                 return true;


                Formit call
                [[!FormIt?
                    &hooks=`spam,name,email,orderInput,redirect,FormItAutoResponder`


                Chunk
                [[+name]] Heeft een bestelling gestuurd: <br />
                <strong>[[+products_output]]</strong>
                You can respond to [[+name]] by email at <a href="mailto:[[+email]]">[[+email]]</a> or phone him at [[+phone]].


                But how do I mqke a difference in weeks, say peccorino week 43 2kg, week 44 3kg?

                I must do it wrong as it returns
                  • 4172
                  • 5,888 Posts
                  your tpl-chunk for the form should look like that:

                  <fieldset>
                      <div class="pur_col1 purlineitem"><img src="[[+image:add_before=`assets/images/`:phpthumbof=`w=100&h=100&zc=1]]" alt="Foto van [[+productname]] " ></div>
                      <div class="pur_col2 purlineitem"><label for="[[+productname]]"><h4>[[+productname]]:</h4><span class="error">[[!+fi.error.[[+productname]]]]</span></label><input type="hidden" name="[[+productname]]" id="[[+productname]]" value="[[+productname]]"/></div>
                      <div class="pur_col4 purlineitem"><label for="[[+productname]]_1">Week [[!getDate:date=`%W`? &offset=`1 Weeks`]]:<span class="error">[[!+fi.error.[[+productname]]_1]]</span></label><input type="text" name="[[+productname]]_1" id="[[+productname]]_1" placeholder='Gewicht' value="[[!+fi.[[+productname]]_1]]" /></div>
                      <div class="pur_col4 purlineitem"><label for="[[+productname]]_2">Week [[!getDate:date=`%W`? &offset=`2 Weeks`]]:<span class="error">[[!+fi.error.[[+productname]]_2]]</span></label><input type="text" name="[[+productname]]_2" id="[[+productname]]_2" placeholder='Gewicht' value="[[!+fi.[[+productname]]_2]]" /></div>
                      <div class="pur_col4 purlineitem"><label for="[[+productname]]_3">Week [[!getDate:date=`%W`? &offset=`3 Weeks`]]:<span class="error">[[!+fi.error.[[+productname]]_3]]</span></label><input type="text" name="[[+productname]]_3" id="[[+productname]]_3" placeholder='Gewicht' value="[[!+fi.[[+productname]]_3]]" /></div>
                      <div class="pur_col4 purlineitem"><label for="[[+productname]]_4">Week [[!getDate:date=`%W`? &offset=`4 Weeks`]]:<span class="error">[[!+fi.error.[[+productname]]_4]]</span></label><input type="text" name="[[+productname]]_4" id="[[+productname]]_4" placeholder='Gewicht' value="[[!+fi.[[+productname]]_4]]" /></div>
                      <div class="pur_col4 purlineitem"><label for="[[+productname]]_5">Week [[!getDate:date=`%W`? &offset=`5 Weeks`]]:<span class="error">[[!+fi.error.[[+productname]]_5]]</span></label><input type="text" name="[[+productname]]_5" id="[[+productname]]_5" placeholder='Gewicht' value="[[!+fi.[[+productname]]_5]]" /></div>
                  </fieldset>
                  


                  your hook some like that (raw idea, untested):

                  <?php
                  
                  $set = $modx->getOption('set', $scriptProperties, '');
                  $input = $modx->fromJson($modx->resource->getTVValue('product'));
                  $output = array();
                  
                  foreach ($input as $row) {
                      if (isset($set) && !empty($set) && ($set != $row['set']))
                          continue;
                      $productname = $modx->getOption('productname', $row, '');
                      $product_orders = '';
                      for ($i = 1; $i++; $i < 5) {
                          $weight = $hook->getValue($productname.'_'.$i);
                          $week = strftime('%W',strtotime('+'.$i.' week'));
                          $product_orders .= $week . ' - ' . $weight . 'kg';
                      }
                  
                      $output[] = $productname . ':' . $product_orders;
                  }
                  $products_output = implode("\n", $output);
                  $hook->setValue('products_output', $products_output);
                  


                  And you need to call that hook before your email-hook, of course
                    -------------------------------

                    you can buy me a beer, if you like MIGX

                    http://webcmsolutions.de/migx.html

                    Thanks!
                    • 10076
                    • 1,024 Posts
                    Seems to be running forever, the webpage gives me a timeout. If I delete the 'orderInput' from the hook however the script runs well. I can t see the error in that script, however I hardley understand it, any suggestions?
                      • 4172
                      • 5,888 Posts
                      ok, here is tested code, which did work for me:

                      $set = $modx->getOption('set', $scriptProperties, '');
                      $input = $modx->fromJson($modx->resource->getTVValue('product'));
                      $output = array();
                       
                      foreach ($input as $row) {
                          if (isset($set) && !empty($set) && ($set != $row['set']))
                              continue;
                          $productname = $modx->getOption('productname', $row, '');
                          $product_orders = '';
                          for ($i = 1; $i <= 5;$i++) {
                              $weight = $hook->getValue($productname.'_'.$i);
                              $week = strftime('%W',strtotime('+'.$i.' week'));
                              $product_orders .= $week . ' - ' . $weight . 'kg <br />';
                          }
                       
                          $output[] = $productname . ': <br />' . $product_orders;
                      }
                      $products_output = implode("<br />", $output);
                      $hook->setValue('products_output', $products_output);
                      
                      return true;
                      
                      [ed. note: Bruno17 last edited this post 12 years ago.]
                        -------------------------------

                        you can buy me a beer, if you like MIGX

                        http://webcmsolutions.de/migx.html

                        Thanks!