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

I've been having issues with handling a successful comment post. After the form is posted successfully, I'm using <cms:if k_process_comment_success> followed by a success message, and then <cms:else/> with <cms:show k_process_comment_error />. However, only the comment error portion works. When a comment is processed successfully, I just get the rest of the form again. I followed the example fairly closely but still can't get it to work.

I've pasted my code below:

Code: Select all
<cms:form method="post">
              <cms:if k_success >
             
                  <cms:process_comment />
                  
                     <cms:if k_process_comment_success >
                     <h1>Hello World</h1>
                  <cms:else />
                     <div class="k_errormessage">
                          <p>
                              Could not post comment! <br>
                              The following error occured while processing your comment:<br>
                              <cms:show k_process_comment_error />
                          </p>
                     </div>
                  </cms:if>
           
              <cms:else />
             
                  <cms:if k_error >
                      <div class="k_errormessage">
                          <h3>Fields incomplete!</h3>
                          <ul>
                              <cms:each k_error >
                                  <li><cms:show item /></li>
                              </cms:each>
                          </ul>
                      </div>
                  </cms:if>
               <div class="form-group">
                   <label for="author" class="control-label"><small>Name *</small></label>
                      <cms:input class="form-control" style="width:50%" type="text" name="k_author" tabindex="1" required="1" value="<cms:show k_member_title/>"/>
               </div>
                  <div class="form-group">
                     <label for="link" class="control-label"><small>Website</small></label>
                      <cms:input class="form-control" style="width:50%" type="text" name="k_link" value="http://" size="22" tabindex="2" value="<cms:get_custom_field 'website' masterpage='members/index.php' page="<cms:show k_member_name/>"/>" />
                  </div>   
                 
                  <div class="form-group">
                     <label for="comment" class="control-label"><small>Comment *</small></label>
                      <cms:input class="form-control" type="textarea" name="k_comment" style="width:93%" rows="10" cols="10" tabindex="3"
                          validator_msg="required=Please enter something as comment"
                          required="1" />
                  </div>
               <cms:input type="text" name="k_email" required="1" value="<cms:show k_member_email/>" style="visibility:hidden;display:none;"/>
                  <cms:input class="btn btn-primary btn-lg" type="submit" value="Submit" name="submit"/>
      
              </cms:if>
          </cms:form>


Thanks,

Sam
Hi,

The best way available now to handle successful form submission is to redirect (i.e. refresh) the page after setting a 'flash message'.

Please see the '1. Session Variables' section of viewtopic.php?f=5&t=7377 for an example.

You'll need to enable the 'sessions' addon in your 'couch/kfunctions.php' file for the flash variables to work.

Hope this helps.
Oh I figured the example that's in the documentation would work. Rather than displaying hello world I really just want to use <cms:send_mail but I couldn't get it to work like I do with other forms in couch.


Thanks,
Sam
Is there a reason why the success case fails to sendmail yet the else case works fine?

Code: Select all
<cms:if k_process_comment_success>
                <cms:send_mail from=k_email_from to=k_email_to subject='Comment posted'>
                    The following comment has been posted at your site:
                    <cms:show k_success />
                </cms:send_mail>
                   
                <div class="k_successmessage">
                    <p>
                        Thank you for the feed back! <br>
                        Your comment awaits moderation and will be published as soon as reviewed by the Admin.
                    </p>
                </div>
            <cms:else />
                <div class="k_errormessage">
                    <p>
                        Could not post comment! <br>
                        The following error occured while processing your comment:<br>
                        <cms:show k_process_comment_error />
                    </p>
                </div>
           
            </cms:if>
The <cms:show k_process_comment_error /> statement in the else block is supposed to spell out the problem encountered. What does it report?
When there is an error processing the comment <cms:show k_process_comment_error /> does work. The problem is that nothing in <cms:if k_process_comment_success> condition executes -- only the else condition.

Sam
nothing in <cms:if k_process_comment_success> condition executes
By nothing do you mean the mail does not get send or nothing at all gets executed i.e. the success message also does not get printed?

If it is the mail problem, we can try debugging that.
Else, I'll need access to your site to see the problem first-hand.

Please let me know.
Thanks.
KK wrote: By nothing do you mean the mail does not get send or nothing at all gets executed i.e. the success message also does not get printed?

The success message does not print. Sending mail works on all my other forms so I don't think it's that.

I also noticed that when I tried to dump_all in the form to see what variable get generated, both k_process_comment_success and k_process_comment_error are not listed.


Sam
Ok, then I'll need to take a look at your setup to try and find the problem.
If the server is online, please PM me FTP + Couch access to it.
After a bit of work with KK, I found out that when define( 'K_COMMENTS_REQUIRE_APPROVAL', 1 ); k_process_comment_success works no problem.

But when it is set to '0' the flow of execution ends at process_comment tag. Since I want to get notification about comments, but not have to approve each one, I was not able to use send_mail the way I normally would.

Here is KK's solution to the problem which worked perfectly.

KK wrote: No direct way but I suppose we can hack together a solution.
Place the highlighted statements around the existing cms:process_comment tag -
<cms:set_flash name='direct_comment_posted' value='1' />
<cms:process_comment />
<cms:set_flash name='direct_comment_posted' value='0' />

The idea is that if the tag redirects, the second statement will not be reached and the flash variable 'direct_comment_posted' will retain a value of '1' (for other cases, the variable will get set to 0).

Now place the following just before the form's opening tag -
Code: Select all
<cms:if "<cms:get_flash 'direct_comment_posted' />" >
    <!-- send_mail here -->
</cms:if>

Send the mail where indicated.

Haven't tried it but should work.

Please let me know.
Thanks
10 posts Page 1 of 1