Problems, need help? Have a tip or advice? Post it here.
3 posts Page 1 of 1
Okay, so here's my situation:

I've created an employee-only area for my organizations website with blog access, various databases, etc., leveraging Couch in fun ways. The issue is with the blog - I want the blog to send a copy of what's posted to myself and the org. director so there's a paper trail (disgruntled employee posts something awful, we have a copy of what was said independent of the blog being removed).

However, the blog staff access is databound to an exterior page, and the standard "frm_blog_content" comes up blank when I post it.

Relevant code:

Code: Select all
<?php require_once ( '../couch/cms.php' ); ?>
<?php require_once( K_COUCH_DIR.'includes/ckeditor/ckeditor.php' ); ?>
<cms:template title="Staff Blog Posting Page" />
<cms:member_check_login />
<cms:if k_member_logged_in >
<!DOCTYPE HTML>
<html>
   <head>
      <cms:embed 'header.html' />
   </head>
   <body>
      <div class="container-fluid">
         <cms:embed 'menu.html' />
         
         <cms:set submit_success="<cms:get_flash 'submit_success' />" />
            <cms:if submit_success >
               <cms:send_mail from='blog_post_alert@xxx.org' to='s***@xxx.org' subject='ALERT: Blog Post'>
*** The following blog was posted ***
By User: <cms:pages masterpage=k_member_template id=k_member_id ><cms:show k_page_title /></cms:pages>

Title: <cms:show frm_k_page_title />

Content: <cms:show frm_blog_content />
   
            </cms:send_mail>
               
               <h4>Success: Your blog has been posted.</h4>
            </cms:if>   

            <cms:form masterpage='blogs.php' mode='create' enctype='multipart/form-data' method='post' anchor='0'>

            <cms:if k_success >
               <cms:db_persist_form
                  _invalidate_cache='0'
               />           
               
               <cms:set_flash name='submit_success' value='1' />
               
               <cms:redirect k_page_link />
            </cms:if>

            <cms:if k_error >
               <div class="error">
                  <cms:each k_error >
                     <br><cms:show item />
                  </cms:each>
               </div>
            </cms:if>   
         
         <label>Blog Type</label>
            <cms:input name='k_page_folder_id' type='bound' />
            <p/>
         
         <label>Blog Title</label>
         <cms:input name='k_page_title' type='bound' />
         <p/>
         
         <label>Blog Content</label>
         <cms:input name='blog_content' type='bound' />
         <p/>
         
         <button type='submit' class='btn btn-default'>Submit</button>
         
               
      </cms:form>

      </div>
      
   </body>
</html>
<cms:else />

   <cms:redirect k_site_link />
   
</cms:if>
<?php COUCH::invoke(); ?>
Hi,

You are using the email code at the wrong place - it is getting executed after the page refreshes and at that point all submitted data is gone. Only the session variable we set remains.

The right place would be in the success condition of the form just before we redirect to refresh the page i.e. here -
Code: Select all
<cms:form masterpage='blogs.php' mode='create' enctype='multipart/form-data' method='post' anchor='0'>

<cms:if k_success >
   <cms:db_persist_form
      _invalidate_cache='0'
   />           
   
   <!-- EMAIL SUBMITTED DATA HERE -->
   <cms:send_mail ..>
        By User: <cms:show k_member_title />
       
        Title: <cms:show frm_k_page_title />

        Content: <cms:show frm_blog_content />
   </cms:send_mail>
   <!-- -->
   
   <cms:set_flash name='submit_success' value='1' />
   
   <cms:redirect k_page_link />
</cms:if>
...
...

Hope this helps.
Thanks! That worked perfectly.
3 posts Page 1 of 1