We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 40762
    • 54 Posts
    Recently I started using FormIt to handle my form requests and suddenly stumbled upon many little issues in terms of retrieving and updating session data. After many hours of debugging and switching between the various snippet and chunk handling my data I finally managed to fix it. In the mean time, I discovered this new event for plugins called OnWebPageInit. This feature turned out to simplify so much my life for updating data session.

    I am opening this post to hear people opinions about this workaround.

    Is it safe? Is it cluttering the server? Do you use this feature too?

    I now only work with formit when in need of filters before submitting my information.

    Mark
      Marc-Andre Audet
    • I'm not sure I follow your methodology here... FormIt is a Snippet, so it executes in-line only where it is encountered (i.e. for most sites, only on a couple pages, e.g. "Contact Us"). Tying code to the OnWebPageInit event will fire for every page request across the site. Usually there is a specific need for using one or the other. I'm not clear why you'd be using FormIt to handle session data -- perhaps you can elaborate?
      • Usually such things can be handled with a formit post-hook. Although the OnWebPageInit is certainly not a new event, as Everett said, why would you want to use a plugin for something that is essentially a form processing function?
          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
          • 40762
          • 54 Posts
          Well for the sake of clarity primary. Everything is in one file no need of a whole bunch of files submit data. I like using core php object as well, so it is another plus for the plugin since with formit I need to use getValues and setValues. With the plugin I don't need to worry about where it is going. As long as I send a new request that refreshes the page and that the required data is attached it will work. I have also had many issues with retrieving updated session with formit. For sending data through ajax request plugins are great too. So much easier than formit.

          Finally, it seems that for retrieving newly submitted data with formit it is a little bit bulky. I dont really get the event nomenclature of formit.

          I feel sometime we rely too much on packages. Why using getResources when we can program our own query with xpdo in few lines of codes?

          Anyway thanks for your reply.

          I am just looking for the best way to use modx that s all. Formit can be very useful in some case.
            Marc-Andre Audet
          • I'm still unclear as to what you're trying to do, so I still can't comment on wether or not your solution is good. Can you give an example of what kind of data you're storing in the session?
              • 40762
              • 54 Posts
              Ok, well in my case, I am programing a quoting system. Through the website, there is different product available that you can add to your quote. I am using a plugin that fires every time the page loads. In this plugin, it looks for specific action (delete, additem, updateitem). I used OnWebPageInit initialy because it sends my request before processing the page. Formit seems to scramble things which cause some refresh to not output the desired data. But moreover, It gets very easy to handle ajax request with OnWebPageInit as I only need to send a request it fires by itself.

              Maybe there is a similar versatile solution with formit with propagating my events through all the website. I am sure that my way causes security leaks as well. who knows...
                Marc-Andre Audet
              • You mean you're posting data around with a specific $_POST['action'] defined? Personally, I would not recommend handling that via a plugin because it's sloppy. You'd be vulnerable to even basic types of vulnerability scans because every page is a potential target. I wouldn't use FormIt for this either, I'd just write a form and make an Ajax post to a dedicated page that listens for posted data. That way you can verify that the incoming requests are coming from the right places (and not, say, from a malicious scanning program or a hacker poking at your site). I'm not sure exactly how you'd have to structure this to meet your needs, but generally speaking, you should only allow as much flexibility as you need (e.g. don't open the garage door if all you need is to crack a window).