We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 24197
    • 21 Posts
    I am attempting to display a form which has PHP code integrated with tables.

    See Screenshot..

    I attempted inserting the entire code from <table> to </table> into a snippet, this did not work.

    I do not want to create a snippet for every instance of php in the page, as 6 pages are necessary each with multiple instances of php.

    What is the best way to create a page with a form containing tables & php code?

    Thank you..

      • 22303 MODX Staff
      • 10,725 Posts
      The easiest way is simply include it and return the output captured in an output buffer, so your snippet would simply consist of something like this:
      <?php
      ob_start();
      include($modx->config['base_path'] . 'assets/snippets/mycode/myform.php');
      $output = ob_get_contents();
      ob_end_clean();
      return $output;
      ?>


      However, it’s better (in my opinion) to separate the markup from the PHP by putting the markup in the document content, or a chunk, and the PHP in a snippet. You can turn the echo’s into placeholders in the content or chunk: consider $modx->setPlaceholder(’sum’, $sum); for instance, and then placing [+sum+] in your content, a chunk, or even a TV, where the <?php echo $sum ?> exists now.