Forum

Thread tagged as: Problem, Error, Comments

Comments showing without moderation

The comments form I'm using seems to just allow anyone to post a comment immediately and when a user refreshes the page after submitting a comment, it duplicates the comment by passing the same PHP command to Perch again.

My Template:

<perch:before>
    <h2>Reviews</h2>
    <perch:if not-exists="commentName">
        <span id="no-reviews">There aren't any reviews for this product yet... :(<br>
        Be the first to review it!</span>
    </perch:if>
    <ul class="ratings">
</perch:before>
        <li id="comment<perch:comments id="commentID" type="hidden" />">
            <img src="//www.gravatar.com/avatar/<perch:comments id="commentEmail" type="email" label="Email" order="2" hash="md5" required="true" />?s=120&d=mm" width="60" height="60" />
            <div style="display: inline-block">
                <perch:if exists="commentURL"><a href="<perch:comments id="commentURL" type="url" label="URL" order="3" />"></perch:if>
                    <strong><perch:comments id="commentName" type="text" label="Name" order="1" required="true" />
                <perch:if exists="commentURL"></a></perch:if></strong>
                <span rel="bookmark" class="date"><perch:comments id="commentDateTime" format="%b %d, %Y" type="date" time="true" label="Date" /></span>
            </div>
            <div class="comment">

                <span class="rating-display">
                    <perch:if id="rating" value="5">
                        <i class="fas fa-star" style="color: #FFBD00"></i>
                        <i class="fas fa-star" style="color: #FFBD00"></i>
                        <i class="fas fa-star" style="color: #FFBD00"></i>
                        <i class="fas fa-star" style="color: #FFBD00"></i>
                        <i class="fas fa-star" style="color: #FFBD00"></i>
                    </perch:if>
                    <perch:if id="rating" value="4">
                        <i class="fas fa-star" style="color: #FFBD00"></i>
                        <i class="fas fa-star" style="color: #FFBD00"></i>
                        <i class="fas fa-star" style="color: #FFBD00"></i>
                        <i class="fas fa-star" style="color: #FFBD00"></i>
                    </perch:if>
                    <perch:if id="rating" value="3">
                        <i class="fas fa-star" style="color: #FFBD00"></i>
                        <i class="fas fa-star" style="color: #FFBD00"></i>
                        <i class="fas fa-star" style="color: #FFBD00"></i>
                    </perch:if>
                    <perch:if id="rating" value="2">
                        <i class="fas fa-star" style="color: #FFBD00"></i>
                        <i class="fas fa-star" style="color: #FFBD00"></i>
                    </perch:if>
                    <perch:if id="rating" value="1">
                        <i class="fas fa-star" style="color: #FFBD00"></i>
                    </perch:if>
                </span>

                <perch:comments id="commentHTML" encode="false" html="true" type="textarea" label="Message (HTML)" order="4" required="true" />
            </div>
        </li>
<perch:after>
    </ul>
</perch:after>

My Page:

    $url = "https://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";

    $productSlug = substr($url, strrpos($url, '/') + 1);

    $productName = perch_shop_product($productSlug, ['template' => 'products/title.html'], true);

    perch_layout('global.top', [
        'title' => $productName,
    ]);

    perch_shop_product($productSlug, [
        'each' => function($item) {
            $comments_form = perch_comments_form($item['sku'], $item['title'], ['template' => 'review_form.html'], true);
            $comments = perch_comments($item['sku'], ['template' => 'review.html'], true);
            $item['comments_form'] = $comments_form;
            $item['comments'] = $comments;
            return $item;
        }
    ]);

    perch_layout('global.footer');
Kevin Wolff

Kevin Wolff 0 points

  • 3 years ago

Kevin, unless you redirect after successful comment, the post data will still exist and refreshing will allow re-submission.

Have you made sure in the options that comments require moderation?

I guess I'll just have the form redirect to the same page again?

As for my settings page, all I have are these options under the Comments section:

Akismet API key: [text input] Delete spam comments: [select field]

Kevin, I do not have a sample of the comments app running to double check... sorry

I was just working (guessing) from my really old, slow brain... and I just can’t seem to recall enough about the app...

Hang in there, more help will come soon :)

Haha, no worries - I appreciate your help a lot. :)

Hussein Al Hammad

Hussein Al Hammad 105 points
Registered Developer

The comments form I'm using seems to just allow anyone to post a comment immediately

Are you testing while still logged into Perch? I haven't used comments in a long time, but I think if you post a comment while logged in, it will publish it straight away.