Hi guys!
There are posts in the forum stating that member module isn't compatible with the commenting system, so it's not possible to show member's name and avatar along with his comment. This is probably true, but I never tested it.
However, experimenting with the member module in the last weeks, I thought I'll should give a try to create "my own" commenting system, as databound forms can be used to submit content from the front end, and displaying submitted content is as easy as listing pages. The only challenge was to connect things together in order to display the correct comments for pages and correct avatar for the member who submitted the comment.
That's what I got so far:
1. We have to create a template for submitting comments, let's call it comments.php, with at least 3 editable region (I used a 4th too, member_name).
2. Create one HTML file for posting comments: post-comment.html and place it into your snippet folder.
3. Create one HTML file for listing comments: list-comment.html and place it into your snippet folder.
4. Embed the 2 html files into the template from which you want to allow posting the comments
That's it! Of course it can be improved with moderation and other stuff, but in this stage it's doing the job. In one of the next days I'll probably implement the moderation too.
There are posts in the forum stating that member module isn't compatible with the commenting system, so it's not possible to show member's name and avatar along with his comment. This is probably true, but I never tested it.
However, experimenting with the member module in the last weeks, I thought I'll should give a try to create "my own" commenting system, as databound forms can be used to submit content from the front end, and displaying submitted content is as easy as listing pages. The only challenge was to connect things together in order to display the correct comments for pages and correct avatar for the member who submitted the comment.
That's what I got so far:
1. We have to create a template for submitting comments, let's call it comments.php, with at least 3 editable region (I used a 4th too, member_name).
- Code: Select all
<cms:template title='Comments' clonable='1'>
<cms:editable name='member_id' required='1' type='text' />
<cms:editable name='member_name' required='1' type='text' />
<cms:editable name='comment' required='1' type='textarea' />
<cms:editable name='page_id' required='1' type='text' />
</cms:template>
2. Create one HTML file for posting comments: post-comment.html and place it into your snippet folder.
- Code: Select all
<h3>POST YOUR COMMENT</h3><br>
<div class="body">
<cms:set submit_success="<cms:get_flash 'submit_success' />" />
<cms:if submit_success >
<div class="alert-success"><p><strong>Success:</strong> Your comment has been submitted successfully.</p></div>
</cms:if>
<cms:pages masterpage=k_member_template id=k_member_id>
<cms:set my_member_name=k_page_title 'global' />
<cms:set my_member_id=k_member_id 'global' />
</cms:pages>
<cms:set my_page_id=k_page_id 'global' />
<cms:form
masterpage='comments.php'
mode='create'
enctype='multipart/form-data'
method='post'
anchor='0'
>
<cms:if k_success >
<cms:db_persist_form
_invalidate_cache='0'
_auto_title='1'
member_name=my_member_name
member_id=my_member_id
page_id=my_page_id
/>
<cms:if k_success >
<cms:set_flash name='submit_success' value='1' />
<cms:redirect k_page_link />
</cms:if>
</cms:if>
<cms:if k_error >
<div class="alert alert-danger"><strong>Error:</strong>
<cms:each k_error >
<br><cms:show item />
</cms:each>
</div>
</cms:if>
<div class="form-group <cms:if k_error_comment >has-error</cms:if>">
<label class="control-label" for="comment">Comment <span class="required">*</span></label><br>
<cms:input class="form-control" id="comment" name="comment" type='bound' value="" style="width:340px;" />
</div>
<cms:if "<cms:not submit_success />" >
<input type="submit" name="submit" value="Submit"/>
</cms:if>
</cms:form>
</div>
3. Create one HTML file for listing comments: list-comment.html and place it into your snippet folder.
- Code: Select all
<h3>COMMENTS</h3>
<cms:set my_news_id=k_page_id 'global' />
<div>
<cms:pages masterpage='comments.php' custom_field="page_id==<cms:show my_news_id />">
<div>
<cms:set mymember_id=member_id 'global' />
<cms:if k_member_logged_in >
<cms:pages masterpage=k_member_template id="<cms:show mymember_id />">
<div id="about_pic"><!-- Start about_pic -->
<cms:show_securefile 'avatar' >
<cms:if file_is_image >
<a href="<cms:cloak_url link=file_id />"><img src="<cms:cloak_url link=file_id thumbnail='1' />" /></a><br />
<cms:else />
<a href="<cms:cloak_url link=file_id />"><cms:show file_name /></a> (<cms:size_format file_size />)
</cms:if>
</cms:show_securefile>
</div><!-- End about_pic -->
</cms:pages>
</cms:if>
<div id="about_right">
<h2><cms:show member_name /> at <cms:show k_page_date/></h2>
<p><cms:show comment /></p>
</div>
</div>
</cms:pages>
</div>
4. Embed the 2 html files into the template from which you want to allow posting the comments
- Code: Select all
<cms:embed 'post-comment.html' />
<cms:embed 'list-comment.html' />
That's it! Of course it can be improved with moderation and other stuff, but in this stage it's doing the job. In one of the next days I'll probably implement the moderation too.