Problems, need help? Have a tip or advice? Post it here.
4 posts Page 1 of 1
Hi KK,

I want to send a email-notification and show a thankyou-message for new comments on the page.
But because I disabled the need for approval, the <cms:process_comment />-tag redirects immediately to show the new comment.

How is it possible though, to send a email and show a message when the comment is successfully processed?
Is it possible to disable the automatic redirect? Or can I use somehow the new session-tags?

Thank you for your Ideas.

Klaus
Hi Nikos,

It won't be possible to disable the automatic redirect. However, as you mentioned, I think we can use the session variables to do what you described.

Suppose, the following is the comment-form code you are using currently
Code: Select all
<cms:form method="post" class="k_form">
   
    <cms:if k_success >
        <cms:process_comment />
        ...

Make the following changes (immediately before and after the 'process_comment' tag:
Code: Select all
<cms:form method="post" class="k_form">
   
    <cms:if k_success >
        <cms:set_session name='send_welcome_mail' value=frm_k_email />
        <cms:process_comment />
        <cms:delete_session 'send_welcome_mail' />
        ...

The first new statement above simply stores the submitted email in a session variable named 'send_welcome_mail'. For un-moderated comments, the 'process_comment' statement that comes next will redirect to a new page so the statement after it will not execute normally. However, for error conditions the control will reach here and the 'send_welcome_mail' session variable gets unset.

The 'send_welcome_mail' session variable is a signal for the redirected page to send the welcome email (and/or show the welcome message etc.).
To do so, we place the following statements in the form (can actually be put anywhere on the page where you wish to show the message)
Code: Select all
<cms:form method="post" class="k_form">

    <cms:if "<cms:get_session 'send_welcome_mail' />">
        <cms:if "<cms:not "<cms:gpc 'comment' method='get' />" />" >
       
            <cms:send_mail from='your@mail.com' to="<cms:get_session 'send_welcome_mail' />" subject='Welcome'>
            Mail's content
            </cms:send_mail>
            <h2>Welcome <cms:get_session 'send_welcome_mail' /></h2>

            <cms:delete_session 'send_welcome_mail' />

        </cms:if>
    </cms:if>
   
    <cms:if k_success >
        <cms:set_session name='send_welcome_mail' value=frm_k_email />
        <cms:process_comment />
        <cms:delete_session 'send_welcome_mail' />

In the code we added above, we check if a session variable named 'send_welcome_mail' is set.
If it is, we go ahead and send the email as well as show the message (making sure to delete the 'send_welcome_mail' variable immediately afterwards so that the actions do not get repeated).

Showing a freshly submitted comment actually entails two redirects (the second being necessary because for comments listed in paginated manner, the new comment might fall on a new page). The first redirect always has a querystring parameter named 'comment' set to the comment's id. We make use of this info to skip the first redirect (<cms:if "<cms:not "<cms:gpc 'comment' method='get' />" />" >).

Hope this helps. Do let me know.
Thanks.
Hi KK,

thank you for your advice, this was the solution.

I was on the right way, but I lacked the knowledge of the two-time redirection.

Thank you again for your outstanding support for all Couch users!

Klaus
You are welcome Klaus :)
4 posts Page 1 of 1