We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 14638
    • 14 Posts
    Hello,
    I have a searched but could not find any info on this.

    Is there a way using standard Revo methods to have a document save event canceled and a ModX manager standard JS popup called that will display a custom error message.

    For example, say that a required TV called "Cars" is not set, would I through a plugin be able to prevent saving and display a JS popup in the manager that says "Please enter a car value"?

    Any help is greatly appreciated.
      • 28042 ☆ A M B ☆
      • 24,524 Posts
      Evo or Revo?

      [edit]Well guess what I found... http://modx.com/extras/package/mmrequirefieldsformanagermanager

      If Evo, you could use the webAlert API function http://wiki.modxcms.com/index.php/API:webAlert combined with sendRedirect. You might need to turn off the feature of validating the server referal value in the site Configuration. Use onDocFormSave, so that it will fire after the resource is available. The user will still be able to ignore the message, but at least he’ll be reminded.

      if(!isset($_POST['whatever'])) {
          $modx->webAlert('Whatever TV is required');
          $modx->sendRedirect(MODX_MANAGER_URL . 'index.php?a=27&id=' . $id,'','REDIRECT_REFRESH');
      };


      If you use onBeforeDocFormSave he’ll get sent back to an empty form; a rather harsh reminder to pay attention.

      Again with Evo, you would probably be better off creating a ManagerManager extension to do it in javascript in the browser before the form is submitted.
        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
        • 14638
        • 14 Posts
        Thanks for your reply. Unfortunately we’re using ModX revolution (sorry for not being clear about that).

        I’ve tried using these methods on the OnDocFormSave event through a plugin but to no avail...

        $modx->setLogTarget('ECHO');
        return $modx->error->failure('TV not filled out');