Problems, need help? Have a tip or advice? Post it here.
19 posts Page 1 of 2
Hi Guys,

So I've converted my old members module system across to extended users, the hardest part of this was rebuilding all comment templates to use the native couch commenting alongside extended users, rather than using custom templates for them all. For some reason, the success and error messages don't ever show.

This is the comment form block below:

Code: Select all
               <div class="comment-form" >
                  <cms:form method="post" class="k_form" action="<cms:show k_page_link />">
                     <cms:if k_success >

                        <cms:process_comment />
                        
                        <cms:if k_process_comment_success>
                           <cms:if k_user_access_level ge '7'>
                              <cms:send_mail from='no-reply@bartonsweb.co.uk' to='contact@bartonsweb.co.uk' subject='New ticket comment'>
                                 A new comment has been added to a ticket.
                                 Ticket url: <cms:show k_page_link />
                                 Ticket subject: <cms:show subject />
                                 Username: <cms:show k_comment_author />
                              </cms:send_mail>
                           </cms:if>
                        
                        <cms:set_flash name='submit_success' value='1' />
                        <cms:redirect k_page_link />
                        <cms:else />
                           <section class=" error--msg">
                                 Could not post comment! <br />
                                 <cms:show k_process_comment_error />
                           </section>                        
                        </cms:if>
                     <cms:else />
                           <cms:if k_error >
                              <section class=" error--msg">
                                    <h4>Fields incomplete!</h4>
                                       <cms:each k_error >
                                          <cms:show item /><br />
                                       </cms:each>
                              </section>
                           </cms:if>
                        
                        <cms:if "<cms:not_empty 'submit_success' />" >
                        <h3>Post a comment</h3>
                        <label for="k_comment">Your reply</label>
                        <cms:input type="textarea" name="k_comment" validator_msg="required=Please enter something as comment" required="1" />
                        <cms:input type="submit" value="Submit" name="submit"/>
                        </cms:if>

                     </cms:if>
                  </cms:form>
               </div>



All of this code works correctly... the comments are saved to the database and show for the relevant page, everything seems to run smoothly which is why I'm confused.

The only success/error message that shows is when the form is not filled in:

Code: Select all
                           <cms:if k_error >
                              <section class=" error--msg">
                                    <h4>Fields incomplete!</h4>
                                       <cms:each k_error >
                                          <cms:show item /><br />
                                       </cms:each>
                              </section>
                           </cms:if



On top of that, I do not receive e-mails when submitting a comment, as you can see there is a send_mail block. Even without the wrapping if statement around it (Checking for admin comments), it still doesn't work.

The weirdest part is on occasion there has been the correct success message shown after commenting, but I've only seen it twice and there were no changes to the template when it worked those times, it also didn't work directly after working. I'm not quite sure what's going wrong so thought I'd post here and see if anyone can see any errors in the code that I have overlooked.

I've never experienced a weird error like this, the behavior seems totally random.

I have elsewhere within the template this code which should show the success message after the comment is submitted, but it doesn't seem to show, though the comment always successfully is added.

Code: Select all
   <cms:set submit_success="<cms:get_flash 'submit_success' />" />
   <cms:if submit_success >
      <section class="user--form success--msg flash--msg">
         <h4>Comment submitted. Please wait for an admin to get back to you.</h4>
      </section>
   </cms:if>


Any help is much appreciated.
Image
I wonder, why do you have both things at the same time:
Code: Select all
action="<cms:show k_page_link />"
<cms:redirect k_page_link />
trendoman wrote: I wonder, why do you have both things at the same time:
Code: Select all
action="<cms:show k_page_link />"
<cms:redirect k_page_link />



Ah, that was my testing - originally it was just redirect, I wasn't sure if that was somehow affecting the set_flash. I've tested both ways and it seems to have no bearing on the results, just forgot to remove the action from the form tag.
Image
To troubleshoot, I'd suggest temporarily removing the redirect and placing <cms:dump /> (or <cms:dump_all />)right after <cms:process_comment />. See if the variables you are using are available and have the right values.

This will help in knowing exactly why a code of block is not executing as expected.

Hope it helps.
KK wrote: To troubleshoot, I'd suggest temporarily removing the redirect and placing <cms:dump /> (or <cms:dump_all />)right after <cms:process_comment />. See if the variables you are using are available and have the right values.

This will help in knowing exactly why a code of block is not executing as expected.

Hope it helps.



Hi KK,

I've just tried this - it seems if there is an error the dump will output a couple of variables, otherwise there is no dump whatsoever if the comment is successfully added.

The only error that works is duplicate content, however. Which triggers the "k_process_comment_error" block of code. Otherwise the comment just submits normally and nothing is output from either dump and dump_all. Moving the dump inside the the <cms:if k_process_comment_success> does nothing either.

:?

EDIT: Something equally perplexing: When the comment triggers the duplicate content error, it seems as though somehow the <cms:if "<cms:not_empty 'submit_success' />" > is triggered and the comment inputs are hidden. Maybe I need the night off, lol. I'm sure there's something stupid causing all of this, I can post the entire template if it helps.
Image
OK, I think I can see the problem -

If the comments don't need approval (happens if the user is 'admin' or above or you have set in config that comments don't need approval), upon successful insertion the PHP routine doing this takes a short-cut and simply redirects. So basically the <cms:process_comment /> tag ends up doing the redirection internally and any Couch code coming after it does not execute.
I really thought you were onto something, but I just tried a normal authenticated user and it seems the exact same behavior is happening.

Same behaviour for the dumps and duplicate content/inputs missing with a normal user too.

:shock: :?
Image
That is strange.
You sure comments are set to require approval in config?
Ah, there we go! I thought I had turned them on but guess I undid it again before I tested.

Thanks, KK. Very difficult to troubleshoot that on my own :D

Can I auto-approve comments within the template, then? Approval isn't needed for this and stops them showing until approved.
Image
Happens :)

As for auto-approval, I think it is a global setting so needs to be done in couch/config.php.
Of course, that would again cause the problem you began this thread with :)

Tell me, the only thing you need is the email after successful insertion, right?
If so, for once we can use PHP to do that. The 'insert_comment' function (in functions.php line 3029) raises an event at every successful insertion. We can hook onto that to send emails.

Let me know if you happen to require any help with it.
19 posts Page 1 of 2
cron