We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 28042 ☆ A M B ☆
    • 24,524 Posts
    Yes, we probably all hate those annoying popup messages. But sometimes they might actually be useful. For example, on login, a popup message could be used to notify the user of ... well, something. And, of course, if our client wants one, then our personal opinion is irrelevant. So here's one easy way to make a reasonably simple popup message on login.

    1. Plugin using OnWebLogin - sets SESSION value
    $_SESSION['loginmessage'] = 'true';


    2. Snippet (ShowLoginMessage) - checks for SESSION value and runs the getResourceField snippet if true
    <?php
    if(isset($_SESSION['loginmessage']) && $_SESSION['loginmessage'] == 'true') {
      $output = $modx->runSnippet('getResourceField', array('id'=>'42', 'field'=>'content'));
      $_SESSION['loginmessage'] = '';
      unset($_SESSION['loginmessage']);
    }
    return $output;


    3. Use snippet in template
    <div id="footer">		
      [[$footerCopyrightBlock]]
      <!-- login message will go here -->
      [[!ShowLoginMessage]]
    </div>


    4. Create resource to contain message - use publish/unpublish and access permissions to show or not, and put message container in its content. The div element and its attributes are required for the JQuery UI dialog to do all of the heavy lifting for you.
    <div id="popupMessage" title="Put Your Message Title Here">
    <p>Lorem ipsum dolor sit amet, tation homero vis in, mea justo scaevola ei, vix tritani corrumpit ut. An nec primis audire facilis. Dolorum phaedrum percipitur sed ut. Ex cum ridens mediocritatem, semper alterum commune ius no, et noster delectus accusata per. Oratio iriure id eum, has ne natum dictas corrumpit.</p>
    </div>


    5. Javascript - JQuery, JQuery UI, JQuery UI theme, link to theme .css file, dialog initialization script
    <link rel="stylesheet" href="assets/js/css/redmond/jquery-ui-1.9.2.custom.min.css" type="text/css" />
    <script language="javascript" src="assets/js/jquery-1.7.2.min.js" type="text/javascript"></script>
    <script language="javascript" src="assets/js/jquery-ui-1.8.11.custom.min.js" type="text/javascript"></script>
    <script>
        $(function() {
            $( "#popupMessage" ).dialog({ 
                 position: { my: "right bottom", at: "right bottom", of: window },
                 hide: {effect: "fade", duration: 3000}
            });
            setTimeout(function(){ $("#popupMessage").dialog("close"); }, 6000);
        });
    </script>
    [ed. note: sottwell last edited this post 13 years, 9 months ago.]
      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
      • 10208 ☆ A M B ☆
      • 1,780 Posts
      Nice Susan! Thank you.

      Got a site where I'm going to need this, if only to be able to prompt the clueless towards their respective tasks. Now, can we apply it to specific usergroups?
        Frogabog- MODX Websites in Portland Oregon
        "Do yourself a favor and get a copy of "MODX - The Official Guide" by Bob Ray. Read it.
        Having server issues? These guys have MODX Hosting perfected - SkyToaster
        • 28042 ☆ A M B ☆
        • 24,524 Posts
        Sure. Just have the snippet check if the user is a member of the required user group/s.

        That's why I used a snippet as a wrapper for the getResourceFields snippet. You can use it to check anything you want.
          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
          For Revolution in OnWebLogin, just surround the snippet action with this:

          if ($user->isMember('somegroup')) {
          
          
          }


          You can also do this, for multiple user groups:

          $groups = array(
              'Editors',
              'CopyEditors',
              'Proofers',
          );
          $isAuthorized = $user->isMember($groups);
          
            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