User message after posting

You can choose to show a message to the user after posting. Use the code below for example:


{# @var commentsWork \twentyfourhoursmedia\commentswork\services\CommentsWorkService #}
{% set commentsWork = craft.commentsWork.service %}

{# check if the user has just posted a comment and provide feedback #}
{% set justPosted = commentsWork.checkJustPosted() %}
{% if justPosted %}
    {% if justPosted.error %}
        <div class="alert alert-danger">
            <p>The comment could not be posted.</p>
        </div>
    {% else %}
        {% if justPosted.status == 'APPROVED' %}
            <div class="alert alert-success"><p>Your comment has been published.</p></div>
        {% elseif justPosted.status == 'PENDING' %}
            <div class="alert alert-warning"><p>Your comment has been posted and is awaiting moderation.</p></div>
        {% else %}
            {# the status is either trashed or spam for some reason,, #}
            <div class="alert alert-danger"><p>Your comment has been posted but has not been not published..</p></div>
        {% endif %}
    {% endif %}
{% endif %}

You can also use this to choose to not display the form again after a user has posted a comment. Beware however that you can only call `commentsWork.checkJustPosted()` just once, after that the message has been reset.


{% set justPosted = commentsWork.checkJustPosted() %}
{% if justPosted %}
    // (show 'you just posted a message')
{% else %}
    // (show the form)
{% endif %}