We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 21092
    • 54 Posts
    neelhtak_backwards Reply #1, 17 years ago
    After all my article pages on my website, I want a series of comments to be viewable. Naturally I want these to be viewable by ALL users, however I want any comments to be added only by registered users who are logged in.
    If the user is not logged in, I would really like a small amount of text to be generated to prompt login.
    At the moment I am using only {{comments}} at the moment.
    What is the code that I should be using?

    Thanks
    Kathleen
      Visit www.katskinner.com for all your expert novel writing tips, tutorials and more.
      • 4041
      • 788 Posts
      Give this snippet a try, I think it would do just what you need:

      Take the code below and create a new snippet named JotComments (to make it easy to remember), paste this in and save. Add the snippet call to the page (or TV) where the comments/text will appear.

      <?php
      /*   JotComments
           usage: call uncached in your document
           [!JotComments!]
      */
      
      $output ='';
      $output .='<div id="commentsAnchor">';
      
      if(!isset($_SESSION['webValidated'])){
          // if the user is not logged in, show this message
          $output .='<p>Please Login to post comments</p>';
      }
      
      // show the comments, note the (&canpost=`Registered Users`) parameter, adding this will only 
      // show the form to add a new comment if the user is logged in and is a member of the 
      // "Registered Users" group
      $output .='[[Jot? &customfields=`name,email` &subscribe=`1` &pagination=`4` &badwords=`dotNet` &canmoderate=`Site Admins` &canpost=`Registered Users`]]';
      
      $output .='</div>';
      
      return $output;
      ?>


      Also note that you can have more than one group of allowed users to post, just make the &canpost=`` parameter a comma seperated list of the group names.
        xforum
        http://frsbuilders.net (under construction) forum for evolution
        • 21092
        • 54 Posts
        neelhtak_backwards Reply #3, 17 years ago
        Breezer,
        I used the code that you helped provide below, and added the call on my article page, however nothing shows up at all - no comments, no input form. This is the same for whether a user is logged in or not.
        The call I used was:
        [!JotComments &canpost=`Registered Users`!]

        The page is not cached. Have I done this correctly?
          Visit www.katskinner.com for all your expert novel writing tips, tutorials and more.
          • 4041
          • 788 Posts
          Try calling it without any parameters, [!JotComments!]

          The embedded snippet call to the actual Jot snippet is the one which you would need to modify to suit, in this part:
          [[Jot? &customfields=`name,email` &subscribe=`1` &pagination=`4` &badwords=`dotNet` &canmoderate=`Site Admins` &canpost=`Registered Users`]]
            xforum
            http://frsbuilders.net (under construction) forum for evolution
            • 21092
            • 54 Posts
            neelhtak_backwards Reply #5, 17 years ago
            Breezer,
            Forgive me for asking what might be a really silly question (but hey we learn buy it tongue)...
            When you say the embedded snippet what do you mean? I call the comments i.e. {{comments}} on the actual article page under the article text.
            If I need an embedded snippet call, where do I put that???


            Thanks
            Kathleen
              Visit www.katskinner.com for all your expert novel writing tips, tutorials and more.
              • 4041
              • 788 Posts
              Ok, lets start over smiley

              Open the Comments chunk for edit, in there you will find the Jot snippet call. Add this parameter to that call:
              &canpost=`groupname` (replace "groupname" with a valid web group name which are allowed to post)
              ex:
              [!Jot? &customfields=`name,email` &subscribe=`1` &pagination=`4` &badwords=`dotNet` &canmoderate=`Site Admins` &canpost=`Registered Users`!]

              Save the chunk, and to see if its working correctly (the form should not show) you will have to log out of the manager and then view the web page as a normal visitor. Once you are sure the comments show, but not the form, then log in to the front as a web user (who should be a member of the group you denoted in the &canpost=`` parameter) and you should see the form to provide a comment.

              Once this part is working as expected we can add the text you require.
                xforum
                http://frsbuilders.net (under construction) forum for evolution
                • 21092
                • 54 Posts
                neelhtak_backwards Reply #7, 17 years ago
                Breezer,
                That worked grin I didn’t even realize there was the embedded bit, I thought it was all php (which I haven’t used before). You learn something every day.

                Any tips on how to get the text to work - otherwise I can just use straight text but something a bit more dynamic would be nice smiley

                Thanks
                Kathleen
                  Visit www.katskinner.com for all your expert novel writing tips, tutorials and more.
                  • 4041
                  • 788 Posts
                  Great smiley now, go into the manager, top menu Elements/Manage Elements/ then click the Snippet tab.

                  Choose New Snippet. Give it a name, make it something easy to remember, ex: CommentText

                  Copy and paste the code below into the content area, making sure there isn’t double start and end <?php ?> tags (easiest way to ensure no duplicates is to delete the ones that are in the form before pasting in the code below):

                  <?php
                  /*   CommentText
                       usage: call uncached
                       [!CommentText!]
                  */
                  
                  $output ='';
                  
                  if(!isset($_SESSION['webValidated'])){
                      // if the user is not logged in, show this message
                      $output .='<p>Please Login to post comments</p>';
                  }
                  return $output;
                  ?>


                  Modify this area of the snippet code to change the message shown:
                  <p>Please Login to post comments</p>

                  Click Save, then open your Comments chunk for editing.

                  Add the following snippet call to the top of the chunk content above the container <div>:
                  [!CommentText!]

                  Your Comments chunk will then look similar to this:
                  [!CommentText!]
                  <div id="commentsAnchor">
                  [!Jot? params.....!]
                  </div>


                  Click Save, and then check the page. If you are not logged in as a web user, the message will show above your comments.
                    xforum
                    http://frsbuilders.net (under construction) forum for evolution
                    • 21092
                    • 54 Posts
                    neelhtak_backwards Reply #9, 17 years ago
                    Breezer,
                    Thank you very much for all your support - it worked perfectly laugh


                    This problem has now been solved.
                      Visit www.katskinner.com for all your expert novel writing tips, tutorials and more.