We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 24731 ☆ A M B ☆
    • 211 Posts
    Hello everyone,

    I am not a programmer but I am really good at copy pasting wink. Anyways, I am trying to create a snippet to make usage of wufoo within modx much simpler. I actually already managed to make it work correctly I am now trying to correctly code the snippet in its proper format and making it somewhat user friendly.

    I have come across a very simple problem, yet I can’t make sense of it.

    I am declaring variables on top of the snippet like this:


    $surveytpl = 'somefile.php'; // This is the PHP File to be used as a template for the Form *REQUIRED
    $formname = 'somename'; // This is the Form Name provided by Wufoo Account admin page *REQUIRED


    and I am trying to access the above variables within a function in the snippet like this:

    // Set the Wufoo Query POST parameters
    function setPostParams(){
    global $formname;
    echo $formname;
    }


    I’ve removed all the coding in this post since I am testing for now.

    The funny thing is that, if I test this as a stand alone PHP file, it works fine. But when I try to do it as a snippet, I always get the empty value as if I was unable to access the variable.

    Am I missing something?

    Thanks.

    Jose R. Lopez
      • 27376
      • 576 Posts
      Variables defined within a snippet are not part of the global variable scope. I recommend passing all necessary variables to the function as parameters. Alternatively, you can use the
      <?php
      $GLOBALS['formname'] = 'somename';
      structure as another solution.
        • 10449
        • 956 Posts
        I’m not quite sure what you’re trying to do, but maybe setPlaceholder / getPlaceholder might also be useful for you (esp. when you also use chunks as part of your setup)
        http://wiki.modxcms.com/index.php/API:setPlaceholder
        http://wiki.modxcms.com/index.php/API:getPlaceholder

          • 24731 ☆ A M B ☆
          • 211 Posts
          Thanks for the suggestions guys, I will give this a try during the weekend and report back.

          J.