We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 3632
    • 22 Posts
    I’m currently working on a couple of plugins that integrate with third party sites such that when a resource is saved, a message is sent to a third party site and a response returned. This is all working fine for me except that I am unclear as to how I would go about communicating back to the user the result of the external request. I would like to be able to show a success or failure message (via MODx.msg.status) to the user based on the response from the third party site AFTER the plugin has run on the OnDocFormSave Event

    Now since the form doesn’t refresh when one saves a resource I guess that means I have to somehow hook in to the success and error javascript events of the form panel but I have no idea how I would go about doing that. Anyone care to give me a pointer?

    Thanks in advance,

    Joe

      • 4172
      • 5,888 Posts
      Is it possible for you, to use the OnBeforeDocFormSave-event?

      I think with a plugin, which listens for OnBeforeDocFormSave you can return a $modx->error->failure, if not succesful.
        -------------------------------

        you can buy me a beer, if you like MIGX

        http://webcmsolutions.de/migx.html

        Thanks!
        • 3632
        • 22 Posts
        Thanks for responding.

        No, can’t really do it that way because I’m sending info to third party sites on the creation of a resource with info about that resource - if for some reason the resource then failed to be created I would have an issue with the third party site referencing a resource that didn’t exist.

        I’m looking through the MODx code to see if I can find an example of how I go about hooking in to the form panel’s events.
          • 3632
          • 22 Posts
          OK, after A LOT of searching through code here’s how its done:

          Ext.ComponentMgr.onAvailable(\'modx-panel-resource\',function(){
          		 			Ext.getCmp("modx-panel-resource").on("success",function(){
          		 				//run your code here to show your status message
          				})});
          


          So I should be able to use a session to store the results from the third party sites in the onDocFormSave event and then pick that value up in the code above which I can output in the onDocFormRender event.
            • 18373 ☆ A M B ☆
            • 3,141 Posts
            I’ve been using $modx->event->_output = ’A message’ from within a plugin on(Before)DocFormSave - that worked.

            Though your solution actually seems a lot more versatile, and I wonder why I didn’t think of that before tongue The only thing lacking here, which you point out you can use sessions for, is transferring data/information. The $modx->event->_output method makes it return an error, so could attempt to fetch the failure instead of success and pop up a success message - if the message returned is what we expected tongue

            Thanks for sharing!
              Mark Hamstra • Developer spending his days working on Premium Extras and a MODX Site Dashboard with the ability to remotely upgrade MODX and extras to make the MODX world a little better.

              Tweet me @mark_hamstra, check my infrequent blog at markhamstra.com, my slightly more frequent ramblings at MODX.today or see code at Github.
              • 3632
              • 22 Posts
              Just for anyone else viewing this, when I thought about it later the session idea is a non-runner as in the onDocFormSave event, nothing is passed back to the form. I then thought about using a TV in the form which I would update on the OnDocFormSave event which I could place my message in and display the updated version of that in my success event but ss Mark later pointed out to me as well, there was a significant change in version 2.1 where the data in the form is no longer fetched as a regular ExtJS data store is via Ajax but is is actually included in the markup loaded with the page and currently there is no way to refresh the data in the form so the TV can not be updated to the latest saved version.

              This left me with the choice of either an unpleasant complete refresh of the page to grab the new TV value or the option of using a connector/processer to grab either the new TV value or the message I wanted to send back. I chose the connector/processor and moved my OnDocFormSave code to the processor which then just sends back my message detailing how the process went to the user in the form of a msg.status message.

              Will blog more completely about this in the next few days.

              Thanks to Mark for helping me tease this out and pointing me at the console and messaging which I hadn’t looked at before.