We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 12379
    • 460 Posts
    I have this bit of code within a snippet. How do I get it to include the html files?

    $header="assets/files/header.html";
    $footer="assets/files/footer.html";
    
    function doFormError($errString) {
    include($header)
        echo "The form you submitted was not complete.<br /><br />";
    include($footer)
        exit;
    }
      Mostly harmless.
      • 11206
      • 73 Posts
      try changing the include to require.
        • 26903
        • 1,336 Posts
        Try ’global $header’ and ’global $footer’ at the top of your function, and why no semicolon after the include statements?
          Use MODx, or the cat gets it!
          • 28042 ☆ A M B ☆
          • 24,524 Posts
          $header="assets/files/header.html";
          $footer="assets/files/footer.html";
          
          function doFormError($errString) {
          global $header, $footer;
          include($header);
              echo "The form you submitted was not complete.<br /><br />";
          include($footer);
              exit;
          }
          

          Learn about variable scope in PHP functions.
          http://www.php.net/variables.scope

          Also be aware that MODx snippets are processed through the eval() function. Any output should be gathered into a variable, then finally the variable should be returned. Using echo() or print() statements will work, but may not work as expected. The output may not appear where you thought it should.
            Studying MODX in the desert - http://sottwell.com
            Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
            Join the Slack Community - http://modx.org
            • 12379
            • 460 Posts
            Thanks - getting this error, however:

            « MODx Parse Error »
            MODx encountered the following error while attempting to parse the requested resource:
            « PHP Parse Error »

            PHP error debug
            Error: doformerror() [function.include]: Failed opening ’’ for inclusion (include_path=’.:/usr/lib/php:/usr/local/lib/php’)
            Error type/ Nr.: Warning - 2
            File: /home/mysite/public_html/manager/includes/document.parser.class.inc.php(769) : eval()’d code
            Line: 127
              Mostly harmless.
              • 26903
              • 1,336 Posts
              Try ’$footer=$modx->config[’base_path’]."assets/files/header.html’. Same for $header. Also put ’global $modx;’ at the top of your snippet
                Use MODx, or the cat gets it!