We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 18913
    • 654 Posts
    I am trying to take an existing PHP app and port it into MODx. It’s got a very simple structure - it some PHP, HTML and some SQL calls. On it’s own it works fine and doesn’t require anything funky.

    But I’m having trouble getting one of the pages to work and I think I’m just missing something very basic. The snippet code is essentially this :
    <?php if (!isset($_POST['submit'])) { ?>
      //output an html form
    <?php
    }
    else {
      //execute php code
    }
    ?>
    


    It outputs the form, but doesn’t reload on "submit" and execute the inner block of PHP.

    I checked the forums and don’t see an obvious example with which to "follow the bouncing ball" and get it to work.

    Can anyone point me in the right direction to using the MODx-friendly way of accomplishing this? Thanks for the patience,
    Matt
    PS If anyone has links to tutorials on porting existing PHP and/or HTML into MODx - other than the material at maryspad - I be interested in seeing that too.
      • 16183
      • 1,390 Posts
      Hi,

      This is for porting existing HTML into MODx

      http://bobsguides.com/porting-your-site-to-modx.html

      Btw, am just curios, why did you divide your if..else statement into two different php blocks? (am no PHP expert; I’m still learning, so wondering if this is some technique?). Thx.

      cheers/k
        • 18913
        • 654 Posts
        Hi,
        Thanks for the link. A (big) part of the problem is that I’m still learning too. The if/else is broken up because that is the way it is in the original code and right now I’m just trying to tease things apart. So figuring out a more optimal bit of PHP is down the road.

        FWIW, the code I’m trying to port is Basic Events Lister (http://www.mevin.com/downloads/basic_events_lister.php). I’m sure there are about a zillion ways to do the same thing - or snippets that do similar things - but I’m just shooting for something basic. And as much as anything else, it’s a learning exercise from which I hope to make a small tutorial.

        Matt
          • 16183
          • 1,390 Posts
          OK, thx for the info. A tut would be nice smiley

          Btw, these are very useful guides to writing MODx snippets..

          http://bobsguides.com/modx-snippets.html
          http://wiki.modxcms.com/index.php/Creating_Snippets

          From what I’ve read, "returning" an output is very important in MODx snippets...

          cheers/k
            • 18913
            • 654 Posts
            Ah! Right! Since I was seeing the form displayed, I overlooked the fact that it wasn’t being formally returned as output.

            By doing this :
            $output .= "";
            
            $output .= //form code 
            $output .= //more form/html code
            
            return $output;
            


            I seem to be moving along.

            Thanks for pointing this out - and for the patience.
            Matt
              • 16183
              • 1,390 Posts
              Nice!

              Am sure you’ll get more concrete pointers from devs in the forums if you get stuck grin

              cheers/k
                • 25663 MODX Staff
                • 12,272 Posts
                Make sure that any form pages are uncached, or any form snippets are called uncached too, or it will process once and you’ll be stuck with the cached results.
                  Ryan Thrash, MODX Co-Founder
                  Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me
                  • 3749
                  • 24,544 Posts
                  You probably know this by now, but snippets can have just one <?php at the beginning and just one ?> at the end. smiley

                  Feel free to post any code here that you’re having trouble getting to work.
                    Did I help you? Buy me a beer
                    Get my Book: MODX:The Official Guide
                    MODX info for everyone: http://bobsguides.com/modx.html
                    My MODX Extras
                    Bob's Guides is now hosted at A2 MODX Hosting