Problems, need help? Have a tip or advice? Post it here.
5 posts Page 1 of 1
I have set up a front-end panel for writers to contribute to our news service using databound forms. I do not want the articles they submit to publish instantly, rather I'd prefer to have a verification email sent to an admin. So far, I have successfully made it so that the submitted pages are unpublished and an email is sent to an admin. But I am unsure how to send the admin a link straight to the admin panel to view it. How would one generate a link to the admin panel link within the <cms:send_mail> link?

Code: Select all
<h1>Article Submission</h1>
<cms:form masterpage='blog.php' mode='create' enctype='multipart/form-data' method='post' anchor='0'>
<cms:if k_success>
<h3>Article successfully submitted</h3>
<cms:send_mail from='<cms:show k_user_title/>' to='' subject='An article has been submitted.'>
Hey Jake,
<br><br>
<cms:show k_user_title/> has submitted an article for review.
<br><br>
Many Thanks,
<br><br>
<cms:show k_user_title/>
</cms:send_mail>
<cms:db_persist_form
_invalidate_cache='0'
k_publish_date='0000-00-00 00:00:00'
/>
<cms:set_flash name='submit_success' value='1' />
</cms:if>
<label for='title'>Article Title</label>
<cms:input type="bound" name="k_page_title"  class='headline' id='title'/>
<div class='innerarticle'>
<cms:input name="description" type="bound" class='description' trust_mode='1'/>
</div>
<label for='author'>Author</label>
<cms:input type="bound" name="author"  class='author' id='author'/>
<label class='imagelabel' for='dynamic'>Image</label>
<cms:input type="bound" name="dynamic"  class='image' id='dynamic'/>
<label class='imagelabel' for='dynamic'>Place</label>
<cms:input type="bound" name="place"  class='image' id='place'/>
<cms:input name="k_page_folder_id" type="bound" class='folderselection'/>
<button class='button newspost' type="submit">Post</button>
</cms:form>


Thanks
Hi,

All 'edit/save/delete' pages in the admin-panel are CSRF protected and carry a security token. This makes it impossible to generate links to these pages externally (i.e. from pages that are not being accessed by the admin). This is a security measure.

So to do what you wish (i.e. send a link to the admin via email clicking which will make her access the edit page of the submitted article directly) we'll have to take a roundabout tack.

Idea is that we simply send a link to the page-view of the article with an additional querystring parameter to indicate that this link is meant for moderation.

In the page-view code, we'll check if the querystring parameter is present (and that the person accessing the page is an admin) and redirect to the actual admin-panel link (we can generate an admin-link form front-end for the admin as shown here - viewtopic.php?f=8&t=7256).

Modify your form code as follows (please note that I'm moving the mail code below the cms:db_persist_form and also refreshing the page after submission) -
Code: Select all
<cms:set submit_success="<cms:get_flash 'submit_success' />" />
<cms:if submit_success >
    <h3>Article successfully submitted</h3>
</cms:if> 

<cms:form masterpage='blog.php' mode='create' enctype='multipart/form-data' method='post' anchor='0'>
    <cms:if k_success>
       
        <cms:db_persist_form
            _invalidate_cache='0'
            k_publish_date='0000-00-00 00:00:00'
        />
       
        <cms:if k_success>
            <cms:send_mail from='<cms:show k_user_title/>' to='jakelazarus@wizardradio.co.uk' subject='An article has been submitted.'>
                Hey Jake,
                <br><br>
                <cms:show k_user_title/> has submitted an article for review.
               
                <br><br>
                Click the following link to moderate the article <br>
                <a href="<cms:add_querystring "<cms:link masterpage='blog.php' page=k_last_insert_page_name />" 'moderate=1' />" >Moderate Page</a>
               
                <br><br>
                Many Thanks,
                <br><br>
                <cms:show k_user_title/>
                Wizard Radio
            </cms:send_mail>
           
            <cms:set_flash name='submit_success' value='1' />
            <cms:redirect k_page_link />
        </cms:if>
    </cms:if>

   
    <label for='title'>Article Title</label>
    ..
    ..
   
</cms:form>   

Important portion of the code above is the following that outputs the link to the page-view (the 'k_last_insert_page_name' variable is set by cms:db_persist_form tag and contains the name of the page just created by it)
Code: Select all
Click the following link to moderate the article <br>
<a href="<cms:add_querystring "<cms:link masterpage='blog.php' page=k_last_insert_page_name />" 'moderate=1' />" >Moderate Page</a>

The link above will only make the admin reach the page-view of the unpublished article of 'blog.php' template and will have 'moderate=1' attached to the URL.

Now in the 'blog.php' template, add the following code (somewhere near the top - just below (but outside) the cms:template block) -
Code: Select all
<cms:if k_page_date='0000-00-00 00:00:00' && "<cms:gpc 'moderate' method='get' />" && k_user_access_level ge '7'>
    <cms:redirect "<cms:admin_link />" />
</cms:if>

The code above checks if the page being accessed is unpublished and the person accessing it is the admin and that the querystring parameter is present. If all conditions match, it uses cms:admin_link tag to generate the link to the admin-panel and redirects the admin to that.

Hope this helps.
Thanks KK,

Unfortunately the link is not present in the sent email.

Code: Select all
<h1>Article Submission</h1>
<cms:set submit_success="<cms:get_flash 'submit_success' />" />
<cms:if submit_success >
<h3>Article successfully submitted</h3>
</cms:if> 
<cms:form masterpage='blog.php' mode='create' enctype='multipart/form-data' method='post' anchor='0'>
<cms:if k_success>
<cms:db_persist_form
_invalidate_cache='0'
k_publish_date='0000-00-00 00:00:00'
/>
<cms:if k_success>
<cms:send_mail from="<cms:show k_user_title/>" to='jakelazarus@wizardradio.co.uk' subject='An article has been submitted.'>
Hey Jake,
<br><br>
<cms:show k_user_title/> has submitted an article for review.
<br><br>
<a href="<cms:add_querystring "<cms:link masterpage='blog.php' page=k_last_insert_page_name />" 'moderate=1' />" >Review Article</a>
<br><br>
Many Thanks,
<br><br>
<cms:show k_user_title/>
Wizard Radio
</cms:send_mail>
</cms:if>
</cms:if>
<label for='title'>Article Title</label>
<cms:input type="bound" name="k_page_title"  class='headline' id='title'/>
<div class='innerarticle'>
<cms:input name="description" type="bound" class='description' trust_mode='1'/>
</div>
<label for='author'>Author</label>
<cms:input type="bound" name="author"  class='author' id='author'/>
<label class='imagelabel' for='dynamic'>Image</label>
<cms:input type="bound" name="dynamic"  class='image' id='dynamic'/>
<label class='imagelabel' for='dynamic'>Place</label>
<cms:input type="bound" name="place"  class='image' id='place'/>
<cms:input name="k_page_folder_id" type="bound" class='folderselection'/>
<button class='button newspost' type="submit">Post</button>
</cms:form>


This is the code. The email says 'moderate the page' but there is no link.

Thanks
You are trying to send HTML in plain-text email.
Please try the following -
Code: Select all
<cms:send_mail debug='1' from="<cms:show k_user_title/>" to='jakelazarus@wizardradio.co.uk' subject='An article has been submitted.'>
Hey Jake,

<cms:show k_user_title/> has submitted an article for review.

<cms:add_querystring "<cms:link masterpage='blog.php' page=k_last_insert_page_name />" 'moderate=1' />

Many Thanks,

<cms:show k_user_title/>
Wizard Radio
</cms:send_mail>

Does this version work? Take a look at the log file too.
It works perfectly!

Thanks again KK
5 posts Page 1 of 1
cron