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

    Firstly if this is considered double posting, please feel free to delete it. I simply post here as I think my query has now move more into the realms of eForm rather than my original query about the Modx API. The original post may be found here:

    http://modxcms.com/forums/index.php/topic,9175.0.html

    I’m fairly confident that my problem is due to my own lack of PHP knowledge, but I’d appreciate any tips on how to work around the problem -- or indeed identify it! smiley

    When i call the following function from the eFormOnBeforeParse event

    function getCategories(&$fields1) {
    //Get child folders
    $pCategories = $modx->getDocumentChildren(26097, 1, 0, 'id, pagetitle, description, alias, parent');
    
    if (!empty($pCategories)) {
    
    $output = "<label accesskey=\"s\" for=\"department\">Subject</label>\n"; 
    $output .= "<select name=\"folder\">\n";
    
    foreach($Categories as $category) {
    $output .= "<option value=\"".$category['id']."\">\"".$category['pagetitle']."\"</option>\n";
    }
    
    $output .= "</select>";
    
    //Assign $output to placeholder
    $output = $fields['categoryOptionBox'];
    return true;
    }
    }
    return '';
    


    The page with the eForm call leads to the following error:

    Fatal error: Call to a member function getDocumentChildren() on a non-object in C:\sokkit\site\modx\manager\includes\document.parser.class.inc.php(733) : eval()'d code on line 9
    


    Any advice much appreciated, and like I said apologies in advance if this is considered double posting (please remove).

    Cheers

    Steve
    • Because you are inside a function, you need to declare:

      global $modx;


      right after your function definition. Otherwise, it thinks you are looking for a variable local to the function called $modx, which does not exist.

      That or you can pass $modx to the function by reference...

      function getCategories(&$modx, &$fields1) {
        • 6437
        • 157 Posts
        Fantastic! grin

        This has been bugging me for a few days, thanks.

        Incidently I couldnt get the pass by reference alternative to work, it throws a Call to Undefined function error.

        Once again thanks smiley

        Steve
          • 30223
          • 1,010 Posts
          Incidently I couldn’t get the pass by reference alternative to work, it throws a Call to Undefined function error.

          That’s because the number of parameters in your event function is already determined by the eForm event calls. They are hard-coded in eForm. In this case the only option is to use:

          global $modx;