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

    eForm has an annoying bug and I need it fixed now so I’m giving it a shot. The problem is that when I nest chunks, the nested chunks are not parsed by the validator. However I can use some pointers regarding the document parsing process in modx.

    I found the function $modx->getChunk. The problem is that that function does not parse the chunks, e.g. I just get the chunk. How would I be able to get the complete parsed chunk?

    example: when I have 2 chunks below, I would like to get the complete form in one string:

    chunk myform
    <form>
    {{personal_details}}
    
    <input type="button" .. >
    </form>
    


    chunk personal_details
    Name: <input type="text" .. >
    Address: <input type="text" .. >
    


    I can regexp all this of course but I expect that that is not quite the way to go
      • 10449
      • 956 Posts
      try $modx->parseChunk();
      http://wiki.modxcms.com/index.php/API:parseChunk
        • 22303 MODX Staff
        • 10,725 Posts
        The parseChunk() function is for passing a simple static array of replacement vars that are replaced in the specified chunk. It does not execute the MODx parsing process.

        I’m not sure why nested chunks don’t get processed (they should), but it’s likely a problem with eForm itself. Anyone more familiar with eForm have a clue to why it doesn’t process the tags nested within chunks?
          • 9021
          • 40 Posts
          hi guys thanks for the help. I looked into the parsechunk function, I don’t think I need that

          I’m not sure how it is supposed to work but it works like this: the getChunk function gets the chunk from the database $modx->getChunk(..), and eForm doesn’t pay attention to eventual nested chunks. When I echo it on screen, the ’{{chunkname}}’ is still there.

          So.. I did fix it like this ($tpl is the initial chunk):

          	preg_match_all("#{{(.*?)}}#",$tpl,$matches);
          	foreach($matches[1] as $name => $value)
          	{
          		$tpl = str_replace("{{".$value."}}", $modx->getChunk($value), $tpl);
          	}
          


          which does works perfectly, but I can imagine there is a better way. Is the getChunk function supposed to return the complete parsed chunk or just as it sits in the database?

          thanks again