We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 24611
    • 3 Posts
    Hello!

    I’m new to ModX, just installed it and set up a basic site. So far it’s fantastic.

    Primarily I’m a web developer. I do custom database driven sites in PHP ... typical stuff like real estate search engines, ecommerce, etc. I’m wondering if ModX will be flexible enough so that I can use it to allow my customers (the site owners) to maintain their static content pages and menus, while still having my custom PHP apps integrated into the site design and framework.

    I’ve read the docs on snippets, widgets, modules and plugins. I also see that there is an API for calling out to the ModX system from external apps, in order to render snippets and such.

    As an example, a site that I just finished building has a handful of static content pages, probably about 20, plus a dynamic content page (an event calendar), plus two ecommerce forms. One is a form for purchasing books, and the other is a form for submitting donations. The two ecommerce forms submit their data to a custom PHP script which charges the credit card and produces a results page for the customer. The events calendar is maintained by the staff through a password protected "staff page" where they can enter events (including date, category, title, price, location, description), modify existing events, or delete events. They also use this backend system to fetch submitted book orders or donations from the DB.

    So, I’m wondering how I would have approached developing this site if I were to use ModX. After reading the docs on snippets, modules and plugins, it seems that the best approach would be to continue to use my own custom scripts for the event calendar and the two order forms, and use the ModX API to wrap their output into the site framework and navigation.

    I guess in the case of the event calendar, I could use a snippet to display the calendar listings in the site, but still use my custom back-end admin app to allow the staff to maintain the events calendar. My only real concern is that with snippets, the code is pasted into a form and saved into a database. I want to use my normal programming editor and upload the files via FTP/SCP ... I don’t want to have to paste code into a web form and submit every time I make a change as I develop.

    Does my approach make sense? If I proceed in this fashion, will I be missing out on some wonderful way of using ModX?

    Thanks for any tips!
      • 30223
      • 1,010 Posts
      The good news is you can keep developing your scripts in your favourite editor and upload them via FTP/SCP. You simply include them in the snippet like thus:

      <?php
      $snipPath = $modx->config["base_path"]."assets/snippets/";
      
      //some snippet parameters
      $param1 = isset($param1) ? $param1 : 'default value';
      
      return include ($snipPath."yourSnippet.php");
      ?>
      


      One thing to remember is that your code should not use echo or print to output anything but instead should return this a s a value. Use output buffering if needed. There’s more ways of doing this off course...
        • 24611
        • 3 Posts
        Okay, that sounds good. How would that work with my donation form example? The way I did the donate form (not using ModX or any CMS) was to have a standard HTML page called donate.shtml with the form, including fields for name, address, etc. and credit card number and expiration date. When the user posts that form, it hits a php file called donate.php which does a background call to authorize.net to validate and charge the card, and then donate.php spits out a confirmation page.

        If I use a snippet to display the donation form, what URL would the <form> action parameter post to? Seems to me that if it posts to the donate.php script, it would take the user "out of" modx at that point, and all the navigation and framework would disappear.

        If the donate snippet form posted to a modx URL, then how would the form field values get to my donate.php script for processing? Is there a way to do this with snippets (or perhaps modules or plugins?) or would I have to keep the donate.php script as an "external" script that calls out to the modx API to generate the framework and navigation for the confirmation screen it generates?
          • 22303 MODX Staff
          • 10,725 Posts
          You should convert donate.php to a snippet and have it send responses within the MODx framework, rather than outside of it. There are some tools (MODxAPI add-on) you could use to integrate some MODx features into the donate.php script, and there will be even easier ways with the new MODx core coming in 0.9.7, but this kind of integration is no less difficult to achieve than converting it to a snippet.

          Form fields work the same in a snippet as they do outside of it (just $_POST variables).