Forum

Thread tagged as: Problem, Add-on-development, Comments

Comments app voting

I'm re-purposing the comments app and can't find any documentation or template examples to get the voting side of things working.

I have a voting form embedded in the comment.html as follows


<div class="row" id="idea<perch:comments id="commentID" type="hidden" />"> <div class="col-sm-12"> <div class="panel panel-onactive"> <div class="panel-heading clearfix"> <p class="panel-title"> <span class="primary col-sm-7 bigtext"><perch:comments id="commentName" type="text" label="Name" order="1" required="true" /></span> <span class="col-sm-5 text-right bigtext"><span class="primary">Current Score: </span>184</span> </p> </div> <div class="panel-body clearfix"> <div class="col-sm-7"> <perch:comments id="commentHTML" encode="false" html="true" type="textarea" label="Message (HTML)" order="4" required="true" /> </div> <div class="col-sm-5 text-right bottom-column"> <p class="icon-row"> <perch:form id="vote" method="post" app="comments"> <perch:input type="hidden" value="THUMB" name="vote_type" /> <perch:input type="hidden" value="<perch:content id="commentID" />" name="commentID" /> <a href="#" class="vote_button" data-votetype="STAR"><span class="fa fa-star-o fa-225x"></span></a> <a href="#" class="vote_button" data-votetype="THUMB"><span class="fa fa-thumbs-o-up fa-225x checked"></span></a> <perch:input type="cms" /> </perch:form> <a href="#" data-toggle="tooltip" title="Public feature: Allows you to share this idea via social media"><span class="fa fa-share-alt fa-225x"></span></a> </p> <p class="smallprint"><a href="">Add to shortlist</a> | <a href="">Report as offensive</a></p> </div> </div> </div> </div> </div>

Is this even possible? Obviously this intention is that form will get repeated for each comment but the page renders the <perch:form...> tags instead of <form...> tags

It would be better to submit the votes via AJAX but how do I ensure that the correct app handles the submission?

Thanks in advance

Caleb

Caleb Evans

Caleb Evans 1 points

  • 6 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

I'm a bit rusty on comment voting - it's one of those features that has never been fully developed.

Perhaps take a look and see if the implementation on 24ways.org helps:

https://github.com/PerchCMS/RunwayExample-24ways/blob/master/perch/templates/comments/vote_preview.html

HI Drew

Can you point me in the direction of posting some data to the correct app in Perch. If I can do that I'll be all set. I just can't quite figure out how to do that without the Perch form system.

Thanks

Drew McLellan

Drew McLellan 2638 points
Perch Support

Use app="perch_comments"

Thanks Drew

I'm at generate today and tomorrow so probably won't do anything with this until the weekend.

I included POST variable app="perch_comments" but this made no difference.

I looked at an existing form, and noticed a base64 encoded variable that is posted with the form. I've replicated this and the votes are being collected and entered into the database.

Do you see any potential problems doing it this way?

Drew McLellan

Drew McLellan 2638 points
Perch Support

You need to have Perch generate the form for you - use <perch:form> tags.

In which case...

In my original post I've shown the template I intended to use but this outputs <perch:form> tags to the browser. How can I solve this problem?

Drew McLellan

Drew McLellan 2638 points
Perch Support

Which page function are you using to render the form?

<php perch_comments(...); ?> is outputting the above template which includes the <perch:form...> tags

I also tried it with a template include but the form tags still get output to the browser.

Drew McLellan

Drew McLellan 2638 points
Perch Support

I think you'll need to use perch_comment() to parse the form, so what you're doing may not be workable.

I've copied and renamed the app so I can make some more detailed changes to the voting system so I will see if I can update the perch_comment function to parse the form.

Thanks for your help.