We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 34120
    • 236 Posts
    Hi, I’m building a site with Revo and I need to integrate a series of forms that have been supplied by another developer. Because of time constraints it’s not practical for me to familiarise him with MODx so I need to keep the files in a format he is comfortable working with.

    I’ve got 3 options in mind:

    1. Step out of MODx completely and leave the form files as complete PHP files. This is probably the simplest approach but will be a pain for me as I’ll lose all the MODx elements, templates etc.

    2. Create the pages in MODx and use snippets to include the form elements. This could be a bit convoluted as I would need to split each form page into 3 includes. Something like this:
    [[!include? &file=`assets/snippets/form-php.php`]]
    <html>
    <head>
    [[!include? &file=`assets/snippets/header-scripts.php`]]
    </head>
    <body>
    [[!include? &file=`assets/snippets/form-content.php`]]
    </body>
    </html>


    3. Pull MODx chunks into the php form files to create the page templates. I think this could work ok but this post has made me question the method.

    I hope that all makes sense, any advice on how best to approach this would be much appreciated.
    Thanks
      • 33983 ☆ A M B ☆
      • 181 Posts
      Have you looked at the FormIt package? I would suggest trying it: http://rtfm.modx.com/display/ADDON/FormIt. You can put the HTML form in a document/webpage and set it up to email you or someone. Look at the examples:

      If this is some complicated form that does some database stuff then I would suggest placing the code into a Snippet. In the docs: http://rtfm.modx.com/display/revolution20/Snippets. But note you can’t have HTML in a snippet so you can return the HTML form as a PHP string or include the HTML as a Chunk. In the docs it is called Templating your Snippet: http://rtfm.modx.com/display/revolution20/Templating+Your+Snippets. Or just look at the getChunk method: http://rtfm.modx.com/display/revolution20/modX.getChunk.
        • 3749
        • 24,544 Posts
        FormIt is a good option.

        If you prefer to roll your own, the usual method is to paste the form code into a Tpl chunk, change any code that creates output into pure HTML with placeholder tags for any output variables, and then move the PHP into a snippet that sets the placeholders.
          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
          • 34120
          • 236 Posts
          Thanks for the replies guys, I don’t think I explained things too well and the code I posted probably confused things even more.

          I’ve built a site in MODx and another developer has created a series of bespoke forms for a reasonably complex registration process. I some how need to integrate these pages with the MODx site, applying the templates etc. As the other developer has never used MODx and wouldn’t know his snippets from his chunks I was planning to leave the files outside of MODx so he can edit them as normal. Is there a way I could pull MODx elements into these pages eg. chunks for the navigation and so on?

          If I’d built this myself from scratch I would have used formIt. In the long run it would be better to recreate the forms with formit but at the present time the other developer has his own js validation etc. that he is comfortable with.

          Not sure if that was any clearer, I’ve confused myself now huh
            • 4172
            • 5,888 Posts
            Quote from: BobRay at Mar 02, 2011, 04:29 PM

            If you prefer to roll your own, the usual method is to paste the form code into a Tpl chunk, change any code that creates output into pure HTML with placeholder tags for any output variables, and then move the PHP into a snippet that sets the placeholders.

            This is the way I would go. Convert all php-codes to snippets and use Chunks for the view-layer. You can include all necessary php-files in your snippet(s) from files, if you want so, also chunks can stay in files.
              -------------------------------

              you can buy me a beer, if you like MIGX

              http://webcmsolutions.de/migx.html

              Thanks!
              • 3749
              • 24,544 Posts
              FYI, it’s really easy to inject JavaScript code into a document before it’s displayed in MODx. It can be loaded from a file or quoted in the code and it can go in the <head> section or at the end of the <body> section:

              http://wiki.modxcms.com/index.php/API:regClientStartupScript

              http://wiki.modxcms.com/index.php/API:regClientScript

              I agree with Bruno17 -- Tpl chunks and a snippet are the best choice, but if you’re determined to run it outside of MODx, you can get access to the methods of the MODx object, like getChunk() and runSnippet() with something like this:

              <?php
              define('MODX_CORE_PATH', 'full/path/to/your/modx/core/');
              define('MODX_CONFIG_KEY', 'config');
              require_once MODX_CORE_PATH . 'model/modx/modx.class.php';
              $modx= new modX();
              $modx->initialize('mgr');
              
                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
                • 7327
                • 195 Posts
                Another issue you might encounter is that support for the form work that the other developer did will be transferred to you, more so if you convert his code into chunks and snippets (since as you said, the other developer doesn’t know MODx). I’m thinking iframes could be another option you can consider. Just something for you to think about.

                Cheers,
                Les