Jump to content

Quick guide to the comments system


ryan

Recommended Posts

I added this code to the template , do i need to do something else?

$limit = 2; // comments to display per page
$start = ($input->pageNum-1) * $limit; 
$selector = "page=$page, sort=-created, start=$start, limit=" . ($limit+1); 

// find the comments. replace "comments" with the name of your comments field
$comments = FieldtypeComments::findComments("comments", $selector); 

// output the comments
echo $comments->render();

// output the pagination links
if($input->pageNum > 1) echo "<a href='./page" . ($input->pageNum-1) . "'>Back</a> ";
if(count($comments) > $limit) echo "<a href='./page" . ($input->pageNum+1) . "'>Next</a>";
Link to comment
Share on other sites

Good morning everyone. I'm having trouble with the Comments fieldtype on my site. I initially thought it was a problem with some setting on the ProcessBlog/MarkupBlog modules I'm using by Kongondo, but he suggested I try a new comment field on a non-blog page and the problem exists there, as well.

I'm not sure where the problem lies, but I'll outline the symptom.

When I attempt to submit a comment on a page, the form redirects me to ./#CommentForm, which loads as the root of the site (the #CommentForm appears in the URL). There is no comment posted, nothing waiting for me in the Comments Manager, etc. No error logged that I can find, just a quiet fail.

Aksimet and redirect are enabled on both the field blog_comments and my newer testing field swmb_comments

Does this sound like anything that anyone has run into? I'm assuming the action of './' and id of 'CommentForm' are default for a reason (as in, they *ought* to work).

Appreciate any help you can provide!

Link to comment
Share on other sites

If you can set up a new local site (or online @ lightning.pw)  running on the stable version of PW (-master) without any third party modules and test your comments code on that, we can begin to troubleshoot what's wrong. Do the same but with a separate -dev version install of PW and see if you still get errors. If you get errors in both, then the problem has to be your code. We can then dissect that...

Link to comment
Share on other sites

So you were able to post and approve comments on both? If so, then it must be a collision with some other code/module on your other site...

Time to proceed with the troubleshooting... - the tedious bit!

One by one, install the modules you have in your 'non-working' site in your new Master and Dev blank test sites....testing if comments work after each module install. What third party modules do you have, apart from Blog? It's probably an autoload module.

Link to comment
Share on other sites

Went through all the modules in /site/modules. LoginRedirect caused an infinite redirect loop and I couldn't get in, so I had to remove that manually. :wacko:  Now my admin can't locate new modules (by class name, URL, or upload) so I had to upload zip files of my existing modules to install them. :P

Anyway, nothing caused it in the fresh install of the master. :unsure:

What would be the next step? I would rather not recreate my site in a clean install, but if I must...

Edited by creativejay
Link to comment
Share on other sites

  • 3 weeks later...

Hi Guys!

Been using the new threaded comments module / system and it's working out really nicely!

Currently when we set the the date / time format of our comment field to relative, it outputs things like 5 minutes ago, 5 hours ago, 5 months ago etc...

I'm trying to build a single language non-English site.

The question is how can we change the language that it outputs?

If anyone could show me some sample code that translates these relative time descriptors to another language, I would be most grateful!!

Cheers and thanks for looking!

Link to comment
Share on other sites

  • 3 weeks later...

I sorted out my earlier problem - turned out the head of the template included a base href call that was what was pushing comment submit to the home page. It's always the little things!

Now that they're working, I'd like to send notification of new comments to the creator of the page the comments are submitted on. This will be different from page-to-page, so I don't want to put everyone's emails in the field's setting for notifications. I looked in the module for a spot to append a page-based value to the email send, but I didn't see it.

What I'm trying to do exactly is better described in this thread I started for this and another email-hooking question.

Thanks!

Link to comment
Share on other sites

  • 4 weeks later...

Dear all,

I can't find any explanation how to change "E-Mail Notifications" from Off to Replies by default. Any ideas?

I found solution from Ryan which works perfect for me.

include("./MyCommentForm.php");
$form = new MyCommentForm($page, $page->comments); 
echo $form->render(); 
Link to comment
Share on other sites

  • 3 months later...

Hey Everyone, 

I would first like to point out that i love the new additions to the comments system. :)

Now what brought me here...

I have a problem with my reply button. When using the $page->comments->renderAll function it works beautifully, however on https://processwire.com/api/fieldtypes/comments/ it shows me how to rename the headlines for each section by doing this...

<?php echo $page->comments->render(array(     
'headline' => '<h2>Read Comments</h2>',     
)); 

echo $page->comments->renderForm(array(
'headline' => '<h2>Join The Discussion</h2>',
));

However when I do this, my reply link in the comments section doesn't work anymore. it doesn't show me nice slide down section for entering a new comment as it did using the renderAll function.

If there is a workaround or some other way of getting it to work while having both headlines text changed, it would be great.

Thanks.

Link to comment
Share on other sites

  • 3 weeks later...

However when I do this, my reply link in the comments section doesn't work anymore. it doesn't show me nice slide down section for entering a new comment as it did using the renderAll function.

If there is a workaround or some other way of getting it to work while having both headlines text changed, it would be great.

Thanks.

I solved this problem by adding this line to the <head> of my page:

<script type='text/javascript' src="/wire/modules/Fieldtype/FieldtypeComments/comments.js"></script>

But I'm not clear on whether that is the correct solution, since it isn't mentioned in any of the docs (that I can find).  

Link to comment
Share on other sites

  • 2 weeks later...

@ryan It seems that successMessage in a custom render call has no effect.

EDIT: There is a pendingMessage string, that is being used. So what is the difference between pendingMessage and successMessage?

EDIT2: Understood it now. When the approval is not needed, successMessage is being used.

I used

echo $page->comments->renderForm(array(
                    'headline' => "<h3>Sag uns deine Meinung</h3>",
                    'successMessage' => "<p class='success'>Danke. Dein Kommentar erscheint, wenn wir ihn freigegeben haben.</p>",
                    'errorMessage' => "<p class='error'>Dein Kommentar konnte nicht gespeichert werden. Bitte überprüfe, ob du alle Felder korrekt ausgefüllt hast, bevor du es erneut probierst.</p>",
                    'processInput' => true,
                    'encoding' => 'UTF-8',
                    'attrs' => array(
                        'id' => 'CommentForm',
                        'action' => './',
                        'method' => 'post',
                        'class' => '',
                        'rows' => 5,
                        'cols' => 50,
                    ),
                    'labels' => array(
                        'cite' => 'Dein Name',
                        'email' => 'Deine E-Mail',
                        'text' => 'Deine Meinung',
                        'submit' => 'Abschicken',
                    ),
                    // the name of a field that must be set (and have any non-blank value), typically set in Javascript to keep out spammers
                    // to use it, YOU must set this with a <input hidden> field from your own javascript, somewhere in the form
                    'requireSecurityField' => '', // not used by default
                ));

But after successful submitting the form, the message "Your comment has been submitted and will appear once approved by the moderator" appears still in english. errorMessage works fine.

Link to comment
Share on other sites

@ryan There is a problem on mobiles after submitting the form because the page is being redirected to #CommentsForm, but the #CommentPostNote is outside of the #CommentsForm, so users on mobile don´t see it. Would be better if the success message is included in the form.

Link to comment
Share on other sites

  • 4 weeks later...
MAYDAY MAYDAY MAYDAY

Hey Everyone, 

I'm looking how to send notifications about comment to user that created the page.

Actually, I found piece of code FieldtypeComments.module:664 $f->addOption(self::notificationCreated, $this->_('Send notifications to user that created the page')); but its commented and not working. 

Maybe it possible to make it like "created_user_id:email" in admin notification settings or something like that?

Thanks for any help.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...