We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 36341
    • 19 Posts
    Hi friends,

    I have just started to work on MODx and i am trying to create login form and stuck, need answers to few of my questions
    1) I have create design in chunk
    2) i want to know how do i link this chunk to snippet, i mean when user click on "Login" button i should get the details in "$_POST" in "process_login" (something like this) snippet.
    using [[~[[*id]]]] submits the page to same page i am not getting how to process the input
    3) i tried googleing "modx form processing" but what all i get is modx plugins for form processing, but i want to learn myself and then using plugins

    Any help would be appreciated.

    Thanks
    Amit
      • 28042 ☆ A M B ☆
      • 24,524 Posts
      If you’re posting the form to the same page then a snippet (uncached!) will have access to the $_POST array. The snippet must be uncached or it won’t be processed on the second (form posting) request as it will have been cached when the form was displayed on the first request.
        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
        • 36341
        • 19 Posts
        Can u please is there any specific condition that chunk name and snippet name should be same so chunk will get linked automatically to snippet ??

        my Chunk "login"
        <center>
        <form name="login" method="POST" action="[[~[[*id]]]]">
          <table cellspacing="2" cellpading="2" width="40%" border="0" class="login">
            <tr><td>Username : </td><td><input type="text" name="uname"></td></tr>
            <tr><td>Password : </td><td><input type="password" name="upass"></td></tr>
            <tr><td></td><td><input type="submit" name="login" value="Login"></td></tr>
          </table>
        </form>
        <center>

        My snippet code
        echo "asas";
        print_r($_POST);
        
          • 28042 ☆ A M B ☆
          • 24,524 Posts
          No. If the form appears on the page, whether from a chunk or directly in the HTML of the template or resource, when it is posted the snippet will independently be able to access the POST.

          Which version of MODx are you using? The snippet must be uncached, in Evo that’s [!Snippet-Name!] and in Revo it’s [[!Snippet-Name]].
            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
            • 3749
            • 24,544 Posts
            There’s no need for the names to match, but you need to set placeholders and use the chunk name in the snippet. You also need placeholder tags in the chunk.

            Is there some reason you’re not using the Login package available in Package Management?
              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
              • 28042 ☆ A M B ☆
              • 24,524 Posts
              BobRay, if he’s just using his own form/snippet combination, then there’s no placeholders involved. Although I also would think it better to use the Login package, since that’s definitely going to work.
                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
                • 36341
                • 19 Posts

                @bobray : Making a login page is not my motto....i just want to learn the flow and want to understand how to process the inputs, linking snippets and chunks etc
                @sottwell : i am using Revolution. scottwell can u please please please embarrassed show me an simple example code how to process input box in snippet.
                i tried google but there are no descriptive examples on gogle. this is what i am palnning to do.... This will be my next post on my blog smiley www.amitpatil.me
                  • 28042 ☆ A M B ☆
                  • 24,524 Posts
                  You mean to actually have the user logged in properly? I don’t use Revo, but what I would recommend that you do is download the Login package and see how it’s done.

                  As far as generic form handling goes, there shouldn’t be a problem accessing the $_POST array when the form is posted. The only reason I can think of is if the snippet is called cached, in which case the page will be taken from cache and the snippet won’t even exist in the cached page, so there’s nothing to deal with the $_POST values.
                    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
                    • 3749
                    • 24,544 Posts
                    Quote from: www.amitpatil.me at May 09, 2011, 02:04 PM


                    @bobray : Making a login page is not my motto....i just want to learn the flow and want to understand how to process the inputs, linking snippets and chunks etc


                    Logins are a particular case and not the best example of how snippets and chunks are used. I’d strongly recommend reading the stuff here:

                    http://rtfm.modx.com/display/ADDON/Login.Login

                    and here:

                    http://rtfm.modx.com/display/ADDON/Login.Tutorials

                    To learn how to use chunks and snippets with forms, the FormIt package is probably the best option: http://rtfm.modx.com/display/ADDON/FormIt.

                    If you get both of those working, you’ll know a lot more about how to do things the MODX way than you’d learn trying to roll your own, IMO.

                    I think that would teach you more than doing your own from scratch.
                      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
                      • 36341
                      • 19 Posts
                      @Bob : I am also feeling like i need to read more...before starting i have read documentation...but now i think that some concepts are not clear to me...I will definitely go through the links u provided.

                      many thanks Bob