We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 36605
    • 70 Posts
    So I realize I could’ve done this with pure HTML but in order to make it more dynamic and also to help sharpen my own coding, I decided to try and write a snippet instead.
    The goal was to supplement and complete an Employee of the Month creation form. I’m using formIt and have three textfields (one RichText), and an image upload. The goal of my snippet was to dynamically create a dropdown for month selection, as well as keep the month’s number value so I could later use it to arrange the awards in a blog like page. Also, it would just take the current year and pass that on just for the sake of getting that in there. The reason for the date specifically with the month widget is that they’re both for date so better to keep those together - especially if I want to transfer it’s usage later on.

    But anyways...the code makes ModX freeze up...ModX stopped itself after it’s parser went nuts on the snippet. I tried installing it on a different ModX test site and still no luck...here’s my code.

    <?php
    $year = date('Y');
    
    $iTpl=$modx->getOption('iTpl',$scriptProperties,'EoM_Inner');
    $oTpl=$modx->getOption('oTpl',$scriptProperties,'EoM_Outer');
    $selClass=$modx->getOption('selClass',$scriptProperties);
    $selName=$modx->getOption('selName',$scriptProperties);
    $months= array (
      1 => 'January', 
      2 => 'February',
      3 => 'March', 
      4 => 'April', 
      5 => 'May', 
      6 => 'June', 
      7 => 'July', 
      8 => 'August',
      9 => 'September',
      10 => 'October',
      11 => 'November',
      12 => 'December'
      );
      
    $x = 1;
    for ($months[x]; x <= 12; $x++) {  
    $properties = array (
      'year' => $year,
      'month' => $months[$x],
      'monthNum' => $x,
      );
    $menu .= $modx->parseChunk($iTpl, $properties);
    }
      
    $output = $modx->parseChunk($oTpl, array('menu'=>$menu,'selClass'=>$selClass,'selName'=>$selName));
    return $output;


    iTpl:
    <option value="[[+monthNum]]">[[+month]]</option>


    oTpl:
    <select name="[[+selName]]" class="[[+selClass]]">[[+menu]]</select>


    If you guys could help me here that’d be awesome. I’m doing this for my most technically developed site yet, and the more I’ve developed this site the more I realize I have trouble with. So all help is appreciated and a good learning experience cool
      • 3749
      • 24,544 Posts
      Try using getChunk() instead of parseChunk().
        Did I help you? Buy me a beer
        Get my Book: MODX:The Official Guide
        MODX info for everyone: http://bobsguides.com/modx.html
        My MODX Extras
        Bob's Guides is now hosted at A2 MODX Hosting
        • 36605
        • 70 Posts
        That’s what I originally had and the same thing occurred. I tried the parseChunk to see if it would be any different. Tried switching back and clearing the cache...still nothing.
          • 3749
          • 24,544 Posts
          That suggests a circular reference, but I don’t see it.

          What do you have in the page content?

          You might try putting the oTpl code in the page and using setPlaceholder() rather than the final getChunk() call.
            Did I help you? Buy me a beer
            Get my Book: MODX:The Official Guide
            MODX info for everyone: http://bobsguides.com/modx.html
            My MODX Extras
            Bob's Guides is now hosted at A2 MODX Hosting
            • 36605
            • 70 Posts
            Still Nothing...the only things I have on the page are my form, a FormIt call, and a LoadRTE (my preferred name for tinymceFE smiley) call.
              • 6228
              • 249 Posts
              I’m assuming this is just a typo on your forum post (note the absence of $ on x variable):
              for ($months[x]; x <= 12; $x++) {  
                lo9on.com

                MODx Evolution/Revolution | Remote Desktop Training | Development
                • 36605
                • 70 Posts
                ...yeah...that was a "copy/paste" error embarrassed

                no, turns out despite putting it through a parser or two, the missing variable call somehow never came up. ha, that’s a good few hours wasted...

                Oh well, but definitely thanks!
                  • 3749
                  • 24,544 Posts
                  So I guess x is always less than or equal to 12. wink
                    Did I help you? Buy me a beer
                    Get my Book: MODX:The Official Guide
                    MODX info for everyone: http://bobsguides.com/modx.html
                    My MODX Extras
                    Bob's Guides is now hosted at A2 MODX Hosting
                    • 36605
                    • 70 Posts
                    Ha. Thank you for the wise words Bob...