We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 12983
    • 108 Posts
    There’s a very strange behaviour when I use:
    $modx->runSnippet('NewsPublisher', $Params);


    Here it is: I have a "test" node (page) with this code:
    [!show_section_editor!]


    "show_section_editor" is a snippet with the following code:
    <?php
    
    $Params['folder'] = 15; // I have a node with id 15, where I want to store the composed article
    $Params['formtpl'] = 'news_form';
    $Params['makefolder'] = '0';
    $Params['rtcontent'] = 'tvnews_content';
    $Params['lang'] = 'it';
    $Params['clearcache'] = '1';
    
    $html = $modx->runSnippet('NewsPublisher', $Params);
    
    ?>
    


    With everything in place, this one works good when I call in my browser:

    http://localhost/myproject/test.html
    


    and I submit the article: it’s stored in the folder node #15.

    The problem is: that 15 has not to be hardcoded, it should be a value from a GET variable. That is, the snippet I need working is:
    <?php
    
    echo $_GET['section'];
    
    $Params['folder'] = $_GET['section']; // the node id where I want to store the composed article is passed via GET
    $Params['formtpl'] = 'news_form';
    $Params['makefolder'] = '0';
    $Params['rtcontent'] = 'tvnews_content';
    $Params['lang'] = 'it';
    $Params['clearcache'] = '1';
    
    $html = $modx->runSnippet('NewsPublisher', $Params);
    
    ?>
    


    So, I call in the browser:
    http://localhost/myproject/test.html?section=15
    


    What I see, is the "15" echoed by the first line of the snippet, then I have the NewsPublisher form; now, when I submit some content, if I look into the node #15 I can’t find it.

    Summying up: if I hardcode the value (15), everything works; while if I take it as the value of a GET variable (which btw echoed is 15, effectively), no way. I’ve also tried with some conversions (intval, strval, settype, ...), but really, no way.

    Please let me know what you think about this issue, and how I should solve it.
    • Is the page cacheable? Make it non-cacheable and see if that makes a diff. Also, just to make sure, try using intval($_GET[’section’]) to get an integer value passed rather than a string.
        • 12983
        • 108 Posts
        Thanks for reply, and what a fast one!
        Problem not solved.

        Making the document uncacheable makes no difference.
        I’ve seen that when I submit the NewsPublisher form, with
        $Params['folder'] = $_GET['section'];
        

        ...the document is created under the "test" node.

        While, if I use:
        $Params['folder'] = intval($_GET['section']);
        

        ...or:
        $Params['folder'] = strval($_GET['section']);
        

        ...the document is created at level 0 (i.e., under the "My MODx Site" top-level node).

        Very strange, uh?
          • 12983
          • 108 Posts
          If no one can discover how I can solve this issue, can someone suggest an alternative way I can achieve the same result?
          I want to call NewsPublisher, saying that the submitted content will be stored as a node into a specified node folder. A dinamically specified one, via a GET parameter. It seemed a rather linear path to me, but it ended up eating all my batteries sad
            • 12983
            • 108 Posts
            I’ve tried replacing the line:
            $Params['folder'] = $_GET['section'];
            


            with:
            $code = "\$Params['folder'] = ". $_GET['section'] .";";
            print_r($code);
            eval($code);
            


            No way. if I call:
            http://localhost/myproject/test.html?section=15
            


            the print_r outputs:
            $Params['folder'] = 15;
            


            ...but when I complete the NewsPublisher form and submit the article, it is written in the top level, not in node 15.

            Just to be clear, I repeat that instead, replacing that line with:
            $Params['folder'] = 15;
            


            ...the snippet just works as expected, with the article written in node 15.