We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 13629
    • 23 Posts
    Let me first say that I’m an experienced LAMP developer and I’ve created a huge number of web forms from scratch.

    My goal:
    My initial goal is to create a form with one text input field. The user enters a value and the field’s value gets inserted into the database. Pretty simple.

    My frustration:
    There doesn’t seem to be a way to fulfill this simple need with MODx. If there is a way, I don’t see people talking about it. I’ve read a lot of forum posts and documentation for things like eForms and FormProcessor (didn’t find clear instructions on how to use either, not sure if they even do what I need).

    I’m pretty new to MODx. I know the basics but I’m not familiar with the "best practices" in general. I could certainly slap something together that works eventually, but I want to make sure I’m not overlooking any good solutions before do something messy.

    Thanks,
    Jason
      • 33372
      • 1,611 Posts
      I use eForm to do this (and practically anything else) in MODx. You can use an eForm event function to insert the value into the database. Check out the posts and wiki on eForm2db for an example, and read through the eForm documentation on its events.
        "Things are not what they appear to be; nor are they otherwise." - Buddha

        "Well, gee, Buddha - that wasn't very helpful..." - ZAP

        Useful MODx links: documentation | wiki | forum guidelines | bugs & requests | info you should include with your post | commercial support options
        • 13629
        • 23 Posts
        Thanks for the reply.

        I spent a while trying to figure out eForm but didn’t find any clear examples.

        The examples I did find had a couple chunks and a snippet call, but I didn’t see any mention of how these parts were supposed to interact with each other.
          • 33372
          • 1,611 Posts
          First read through the eForm documentation (which is in the snippet folder) and get a regular eForm working properly. That’s where the chunks come into play, and you’ll understand it once you go through those docs. Then look at how to add a function as an eForm event (which is what will add your data to the database). There are several examples out there, but you should start with the basic eForm first so you understand how the pieces fit together. If you have trouble, post again here or in the eForm subforum.
            "Things are not what they appear to be; nor are they otherwise." - Buddha

            "Well, gee, Buddha - that wasn't very helpful..." - ZAP

            Useful MODx links: documentation | wiki | forum guidelines | bugs & requests | info you should include with your post | commercial support options
            • 13629
            • 23 Posts
            Thanks for the reply. I took another look at the eForm docs and things became more clear. In case anyone else reading this is having the same frustrations, here’s how I achieved success:

            1. I created a blank document that uses the template "Artist Registration Form."
            2. My Artist Registration Form template looks like this:
            [!eForm? &formid=`artistRegistrationForm` &to=`[email protected]` &tpl=`artistRegistrationForm` &report=`artistRegistrationEmail` &thankyou=`artistRegistrationSuccess` &subject="Web site feedback"!]
            

            3. I created a chunk called artistRegistrationForm. It looks like this:
            <div class="normal-form">
            <h1>Artist Registration Form</h1>
            [+validationmessage+]
            <form method="post" action="[~[*id*]~]" id="artistRegistrationForm">
            <div>
            <label for="first-name">First Name</label>
            <input type="text" name="first-name" id="first-name" eform="First Name::1:" />
            </div>
            
            <div>
            <label for="last-name">Last Name</label>
            <input type="text" name="last-name" id="last-name" eform="Last Name::1:" />
            </div>
            
            <div>
            <label for="artist-name">Artist Name</label>
            <input type="text" name="artist-name" id="artist-name" eform="Artist Name::1:" />
            </div>
            
            <div>
            <label for="email">E-mail Address</label>
            <input type="text" name="email" id="email" eform="E-mail Address::1:" />
            </div>
            
            <div>
            <label for="city">City</label>
            <input type="text" name="city" id="city" eform="City::1:" />
            </div>
            
            <div>[[StateSelect]]</div>
            <div>[[CountrySelect]]</div>
            
            <div><input type="submit" value="Submit" /></div>
            </form>
            </div><!-- div class="normal-form" -->
            

            4. I also created two other chunks, artistRegistrationEmail and artistRegistrationSelect. Those can be anything, though, and don’t matter for the sake of this example. The [[StateSelect]] and [[CountrySelect]] snippets can also be ignored/omitted.

            After those steps were complete, I just visited the Artist Registration Form document in the browser and it worked.
              • 13629
              • 23 Posts

              &eFormOnValidate (optional)
              Expects a function name. This function will be called directly after the form validation has taken place. You can use this event to add your own extra validation logic. The function should accomodate the following parameters

              Where does it expect the function to be defined?

              Thanks
                • 13629
                • 23 Posts
                Nevermind - answered my own question. From /eform/docs/eform_example_events.htm:

                All very well that we’ve written a function but how do we get it into MODx? I’m sure there’s multiple ways of doing that but I’ve simply created an extra snippet called eFormEvent with the ’createJobNumber’ function as the only content. That way it’s only loaded when using the form. To make it available to eForm we place a call to this snippet on the same page, just before we call the eForm snippet (It needs to be first as otherwise it’s not parsed by the time eFrom needs it).
                  • 33372
                  • 1,611 Posts
                  Glad to see you figured it all out. The eForm documentation is very good, so it’s always the best place to start.
                    "Things are not what they appear to be; nor are they otherwise." - Buddha

                    "Well, gee, Buddha - that wasn&#39;t very helpful..." - ZAP

                    Useful MODx links: documentation | wiki | forum guidelines | bugs & requests | info you should include with your post | commercial support options
                    • 18270
                    • 68 Posts
                    For ModX revolution, try FormItBuilder (In combination with FormIt)
                    http://modx.com/extras/package/formitbuilder
                    http://modxrevo.datawebnet.com.au/
                      • 28042 ☆ A M B ☆
                      • 24,524 Posts
                      With the latest versions of eForm you can specify the snippet that contains the function in an eForm property, so you don't need to use your extra snippet's tags.

                      &runSnippet (new in 1.4.4) (optional)

                      Expects a snippet name. Snippet will be run before any eForm handling. One parameter, the &&formid will be passed to the snippet. Any return value from the snippet is discarded. This can be used to insert functions as an alternative to declaring a separate snippet in the document. Sadly eForm will silently ignore a snippet that does not exist due to the way $modx->runSnippet handles snippet return values.

                      I've attached a handy cheat sheet that I wouldn't be without when using Evo and eForm.
                        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