Forum

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

Adding Rating system to Comments App

Has anyone here added a star rating to the Comments App? I am trying to do this and would love it if someone has already done this and can help me find the SQL insert query, or do it for me, as a paying job of course.

Kim Mazzola

Kim Mazzola 0 points

  • 5 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

You should be able to add a rating field to the comments form.

Drew, Yes, I did that, that's the easy part. Perhaps I'm not clear on this, but don't I have to alter the sql insert statement to make sure the additional fields are added to the table? And, don't I have to create a field in the comments_app table to store the rating? That's where I need the help.

And, while I have your attention, do I need to install the forms_app in order to process the comments_app form? Or does that come with the comments app? I can't find mention of that in the docs.

Thank you.

Drew McLellan

Drew McLellan 2638 points
Perch Support

No, you don't need to do that - just add the field to both the comment form and the comment display.

Wonderful, thank you. I had found the line of code to display comments on a page, but now I can't find it. Can you point me in the right direction? Even a search of your docs don't show me what I'm looking for.

Drew McLellan

Drew McLellan 2638 points
Perch Support

Drew,

I'm sorry, I'm pretty dense. But, I'm using this as a separate page not linked to a product or blog. Simply a page where you can leave a comment on the service you received. More like a review. So, There won't be any identifier. Is there a way to display all the submitted comments at once? Without the need to pass an ID?

Drew McLellan

Drew McLellan 2638 points
Perch Support

Just make up an identifier - something like "general" would do. Just give it something.

Thank you, again.

I am submitting the form and it's not being inserted into the database table. I turned on debug and when the initial form page loads this is the output on that page

Array
(
    [type] => 8
    [message] => Undefined index: id
    [file] => /Volumes/OWC_Work_files/work/PHP-Sites/dev.diamondtransportation.com/perch/core/lib/PerchTemplatedForm.class.php
    [line] => 426
)

Also upon a successful submission I get the following in debug:

PerchAPI_SubmittedForm Object
(
    [app_id] => perch_comments
    [version] => 1
    [Lang:PerchAPI_SubmittedForm:private] => PerchAPI_Lang Object
        (
            [lang_dir] => /Volumes/OWC_Work_files/work/PHP-Sites/dev.diamondtransportation.com/perch/addons/apps/perch_comments/lang
            [lang_file] => /Volumes/OWC_Work_files/work/PHP-Sites/dev.diamondtransportation.com/perch/addons/apps/perch_comments/lang/en-gb.txt
            [lang] => en-gb
            [translations:PerchAPI_Lang:private] => 
            [to_add:PerchAPI_Lang:private] => Array
                (
                )

        )

    [data] => Array
        (
            [commentName] => kim
            [commentEmail] => kim@kim.com
            [rating] => 5
            [commentHTML] => this is my review
            [parentID] => 
            [parentTitle] => 
            [submitComment] => Submit
        )

    [files] => Array
        (
        )

    [antispam] => 
    [form_attributes] => Array
        (
            [id] => comment
            [method] => post
            [app] => perch_comments
        )

    [page] => /reveiws.php
    [id] => comment
    [formID] => comment
    [templatePath] => /templates/content/comment_form.html
    [templateContent:PerchAPI_SubmittedForm:private] => 



Leave a Review



            Name

            Required




            Email

            Required
            Check format of address




Rating







































            Review

            Required




            " />
            " />









Thank you. Your review has been submitted and will appear on the site once approved.





    [filetypes:PerchAPI_SubmittedForm:private] => Array
        (
        )

    [timestamp:PerchAPI_SubmittedForm:private] => 1475233753
    [mimetypes] => Array
        (
        )

)

Any help would be greatly appreciated. I am lost from here.

Rachel Andrew

Rachel Andrew 394 points
Perch Support

What does your template look like? And, please post your Diagnostics Report too - thanks!

When you say template, do you mean the page template or the content templates? The content template is your standard form just altered to add a star rating:

<perch:form id="comment" method="post" app="perch_comments">
    <fieldset>
       <legend>Leave a Review</legend>
        <div>
            <perch:label for="commentName">Name</perch:label>
            <perch:input type="text" id="commentName" required="true" label="Name" antispam="name" />
            <perch:error for="commentName" type="required">Required</perch:error>
        </div>
        <div>
            <perch:label for="commentEmail">Email</perch:label>
            <perch:input type="email" id="commentEmail" required="true" label="Email" antispam="email" />
            <perch:error for="commentEmail" type="required">Required</perch:error>
            <perch:error for="commentEmail" type="format">Check format of address</perch:error>
        </div>
         <p><perch:label for="rating">Rating</perch:label></p>

    <div class="list_rating">
    <ul>
    <li><perch:input type="radio" name="rating" id="ratingStar5" value="5" /> <i class="fa fa-star" aria-hidden="true"></i>
<i class="fa fa-star" aria-hidden="true"></i>
<i class="fa fa-star" aria-hidden="true"></i>
<i class="fa fa-star" aria-hidden="true"></i>
<i class="fa fa-star" aria-hidden="true"></i>
</li>
    <li><perch:input type="radio" name="rating" id="ratingStar4" value="4" /> <i class="fa fa-star" aria-hidden="true"></i>
<i class="fa fa-star" aria-hidden="true"></i>
<i class="fa fa-star" aria-hidden="true"></i>
<i class="fa fa-star" aria-hidden="true"></i>
</li>
    <li><perch:input type="radio" name="rating" id="ratingStar3" value="3" /> <i class="fa fa-star" aria-hidden="true"></i>
<i class="fa fa-star" aria-hidden="true"></i>
<i class="fa fa-star" aria-hidden="true"></i>
 </li>
<li><perch:input type="radio" name="rating" id="ratingStar2" value="2" /> <i class="fa fa-star" aria-hidden="true"></i>
<i class="fa fa-star" aria-hidden="true"></i>
 </li>
<li><perch:input type="radio" name="rating" id="ratingStar1" value="1" /> <i class="fa fa-star" aria-hidden="true"></i>
</li>
      </ul>
      </div>
        <div>
            <perch:label for="commentHTML">Review</perch:label>
            <perch:input type="textarea" id="commentHTML" required="true" label="Message" antispam="body" />
            <perch:error for="commentHTML" type="required">Required</perch:error>
        </div>
        <div>
            <perch:input type="hidden" id="parentID" value="<perch:comments id="parentID" />" />
            <perch:input type="hidden" id="parentTitle" value="<perch:comments id="parentTitle" />" />
            <perch:input type="submit" id="submitComment" value="Submit" />
        </div>

    </fieldset>
    <perch:success>
        <p>Thank you. Your review has been submitted and will appear on the site once approved.</p>
    </perch:success>

</perch:form>

My Diagnostics Report:

Perch: 2.8.25
Production mode: Development (10)
Installed apps: content (2.8.25), assets (2.8.25), categories (2.8.25), perch_forms (1.8.3), perch_comments (1.2)
DB driver: PDO
DB tables: perch2_categories (0), perch2_category_counts (0), perch2_category_sets (0), perch2_comments (0), perch2_comments_votes (0), perch2_content_index (941), perch2_content_items (180), perch2_content_regions (19), perch2_navigation (0), perch2_navigation_pages (0), perch2_page_templates (6), perch2_pages (7), perch2_resource_log (256), perch2_resource_tags (0), perch2_resources (58), perch2_resources_to_tags (0), perch2_settings (16), perch2_user_passwords (0), perch2_user_privileges (28), perch2_user_role_privileges (16), perch2_user_roles (2), perch2_users (1)
Users: 1
App runtimes:

<?php
    $apps_list = array(
        'content', 
        'categories',
        'perch_comments',
        'perch_forms',
    );

Scheduled tasks for perch_comments: delete_spam_comments (1440 mins)
Editor plug-ins: markitup
H1: b51666ad0e7bc8a5e2b69455d137d176
L1: dd96e112a72330617ef9f36ffe1b2c15
F1: dc1fef2ad0fcd9f943c02ebb43d85dbc
headerColour: #ffffff
content_singlePageEdit: 0
helpURL:
siteURL: /
hideBranding: 1
content_collapseList: 1
lang: en-gb
update_2.8.25: done
latest_version: 2.8.15
on_sale_version: 2.8.31
headerScheme: light
dashboard: 0
hide_pwd_reset: 0
content_hideNonEditableRegions: 0
content_frontend_edit: 0
logoPath: /perch/resources/1455575632_diamond-transportation-logo.png
PERCH_DEVELOPMENT: 10
PERCH_STAGING: 50
PERCH_PRODUCTION: 100
PERCH_DB_USERNAME: root
PERCH_DB_SERVER: localhost
PERCH_DB_DATABASE: diamond_trans
PERCH_DB_PREFIX: perch2_
PERCH_TZ: America/New_York
PERCH_EMAIL_FROM: kim@createacardinc.com
PERCH_EMAIL_FROM_NAME: Kim Mazzola
PERCH_LOGINPATH: /perch
PERCH_PATH: /Volumes/OWC_Work_files/work/PHP-Sites/dev.diamondtransportation.com/perch
PERCH_CORE: /Volumes/OWC_Work_files/work/PHP-Sites/dev.diamondtransportation.com/perch/core
PERCH_RESFILEPATH: /Volumes/OWC_Work_files/work/PHP-Sites/dev.diamondtransportation.com/perch/resources
PERCH_RESPATH: /perch/resources
PERCH_PRODUCTION_MODE: 10
PERCH_DEBUG: 1
PERCH_HTML5: 1
PERCH_YOUTUBE_API_KEY: AIzaSyBacpY4afW3ZixkSIjfgeOPocm-nX-wXhs
PERCH_RUNWAY:
PERCH_ERROR_MODE: DIE
PERCH_DATE_LONG: %d %B %Y
PERCH_DATE_SHORT: %d %b %Y
PERCH_TIME_SHORT: %H:%M
PERCH_TIME_LONG: %H:%M:%S
PERCH_RUNWAY_ROUTED:
PERCH_STRONG_PASSWORDS:
PERCH_PREVIEW_ARG: preview
PERCH_TEMPLATE_PATH: /Volumes/OWC_Work_files/work/PHP-Sites/dev.diamondtransportation.com/perch/templates
PERCH_DEFAULT_DOC: index.php
PERCH_DEFAULT_EXT: .php
PERCH_RWD:
PERCH_HTML_ENTITIES:
PERCH_SSL:
PERCH_STRIPSLASHES:
PERCH_PROGRESSIVE_FLUSH: 1
PERCH_AUTH_PLUGIN:
PERCH_DB_CHARSET: utf8
PERCH_DB_PORT:
PERCH_DB_SOCKET:
PERCH_SESSION_TIMEOUT_MINS: 20

Hosting settings

PHP: 7.0.0
Zend: 3.0.0
OS: Darwin
SAPI: apache2handler
Safe mode: not detected
MySQL client: mysqlnd 5.0.12-dev - 20150407 - $Id: 7e72f9690b1498a1bead7a637c33a831c0d2f655 $
MySQL server: 5.5.42
Free disk space: 301.00 GB
Extensions: Core, date, libxml, openssl, pcre, sqlite3, zlib, bcmath, bz2, calendar, ctype, curl, dom, hash, fileinfo, filter, ftp, gd, SPL, iconv, intl, json, ldap, mbstring, session, standard, mysqlnd, PDO, pdo_mysql, pdo_sqlite, Phar, posix, Reflection, mysqli, SimpleXML, soap, sockets, exif, tokenizer, wddx, xml, xmlreader, xmlwriter, xsl, zip, apache2handler, imap, mcrypt, pgsql, pdo_pgsql
GD: Yes
ImageMagick: No
PHP max upload size: 32M
PHP max form post size: 32M
PHP memory limit: 128M
Total max uploadable file size: 32M
Resource folder writeable: Yes
Session timeout: 24 minutes
Native JSON: Yes
Filter functions: Yes
Transliteration functions: Yes
HTTP_HOST: dev.diamondtransportation.com:9001
HTTP_USER_AGENT: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.10; rv:49.0) Gecko/20100101 Firefox/49.0
HTTP_ACCEPT: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
HTTP_ACCEPT_LANGUAGE: en-US,en;q=0.5
HTTP_ACCEPT_ENCODING: gzip, deflate
HTTP_REFERER: https://dev.diamondtransportation.com:9001/perch/core/settings/diagnostics/
HTTP_COOKIE: _ga=GA1.2.1652872791.1474485908; __utma=211734912.1652872791.1474485908.1475165913.1475232681.8; __utmz=211734912.1474485908.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); __zlcmid=cjfrujklPuyfxh; cmsa=1; __utma=55649598.1652872791.1474485908.1474538709.1475169810.3; __utmz=55649598.1474487651.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); __utmc=211734912; __utmc=55649598; __utmb=211734912.0.10.1475232681; _gat=1; PHPSESSID=2a5cc71e431d40871df58b133997945b
HTTP_CONNECTION: keep-alive
HTTP_UPGRADE_INSECURE_REQUESTS: 1
PATH: /usr/bin:/bin:/usr/sbin:/sbin
SERVER_SOFTWARE: Apache
SERVER_NAME: dev.diamondtransportation.com
SERVER_ADDR: ::1
SERVER_PORT: 9001
REMOTE_ADDR: ::1
DOCUMENT_ROOT: /Volumes/OWC_Work_files/work/PHP-Sites/dev.diamondtransportation.com
SERVER_ADMIN: you@example.com
SCRIPT_FILENAME: /Volumes/OWC_Work_files/work/PHP-Sites/dev.diamondtransportation.com/perch/core/settings/diagnostics/index.php
REMOTE_PORT: 51965
GATEWAY_INTERFACE: CGI/1.1
SERVER_PROTOCOL: HTTP/1.1
REQUEST_METHOD: GET
QUERY_STRING: extended
REQUEST_URI: /perch/core/settings/diagnostics/?extended
SCRIPT_NAME: /perch/core/settings/diagnostics/index.php
PHP_SELF: /perch/core/settings/diagnostics/index.php
REQUEST_TIME_FLOAT: 1475235359.73
REQUEST_TIME: 1475235359
argc: 1

~~~

Rachel Andrew

Rachel Andrew 394 points
Perch Support

Ok so the first thing to do would be to update Perch, you are a few versions back and any advice we give will be based ont he latest version.

It's generally a good idea to update before doing any additional development work on a project as we fix and improve things with each release.

Once you've updated let us know if the issue still exists.

I saw that I'm outdated and I'm updating now. Will report back shortly. Thank you.

I copied the core folder into the site and, unfortunately, the same response. The review is not being inserted into the db.

Drew McLellan

Drew McLellan 2638 points
Perch Support

What problem are you seeing?

I fill in the form on the page and hit submit and the submission is not inserted into the database. On the page, the success message is displayed, but again, it hasn't been inserted into the database. In the admin, there are no comments pending, or approved. No comments at all.

Drew McLellan

Drew McLellan 2638 points
Perch Support

Is the above the whole of the debug output when submitting a comment?

Yes I copied everything that was output with the debug.

Drew McLellan

Drew McLellan 2638 points
Perch Support

There should be a lot more than that, so perhaps something is throwing an error.

Is there anything in the server error log?

here is the full report from a submission. If this isn't everything, then I don't know what you need. To be honest with you, I'm using Mamp PRO on a mac. I don't know how to find server logs. That's a bit over my head.

Time    Δ   Debug Message
0.0201  0   [17] SELECT DISTINCT settingID, settingValue FROM perch2_settings WHERE userID=0
0.3068  0.2867  

PerchAPI_SubmittedForm Object
(
    [app_id] => perch_comments
    [version] => 1
    [Lang:PerchAPI_SubmittedForm:private] => PerchAPI_Lang Object
        (
            [lang_dir] => /Volumes/OWC_Work_files/work/PHP-Sites/dev.diamondtransportation.com/perch/addons/apps/perch_comments/lang
            [lang_file] => /Volumes/OWC_Work_files/work/PHP-Sites/dev.diamondtransportation.com/perch/addons/apps/perch_comments/lang/en-gb.txt
            [lang] => en-gb
            [translations:PerchAPI_Lang:private] => 
            [to_add:PerchAPI_Lang:private] => Array
                (
                )

        )

    [data] => Array
        (
            [commentName] => kim
            [commentEmail] => kim@kim.com
            [rating] => 5
            [commentHTML] => this is the review submission form. Testing it out.
            [parentID] => 
            [parentTitle] => 
            [submitComment] => Submit
        )

    [files] => Array
        (
        )

    [antispam] => 
    [form_attributes] => Array
        (
            [id] => comment
            [method] => post
            [app] => perch_comments
        )

    [page] => /reveiws.php
    [id] => comment
    [formID] => comment
    [templatePath] => /templates/content/comment_form.html
    [templateContent:PerchAPI_SubmittedForm:private] => 



Leave a Review



            Name

            Required




            Email

            Required
            Check format of address




Rating







































            Review

            Required




            " />
            " />









Thank you. Your review has been submitted and will appear on the site once approved.





    [filetypes:PerchAPI_SubmittedForm:private] => Array
        (
        )

    [timestamp:PerchAPI_SubmittedForm:private] => 1475270781
    [mimetypes] => Array
        (
        )

    [redispatched] => 
)

0.3068  0   
0.3097  0.0029  [1] SELECT * FROM perch2_pages WHERE pagePath='/reveiws.php' LIMIT 1
0.3129  0.0031  Using template: /templates/pages/attributes/default.html
0.313   0.0002  Using sub-template: /templates/pages/attributes/seo.html
0.3134  0.0004  [7] SELECT * FROM perch2_pages WHERE pageNew=0 AND pageHidden=0 AND pageDepth >=0 AND pageDepth<=1 ORDER BY pageTreePosition ASC
0.3138  0.0004  [1] SELECT pageTreePosition FROM perch2_pages WHERE pagePath='/reveiws.php' LIMIT 1
0.314   0.0002  [1] SELECT pageID FROM perch2_pages WHERE pageTreePosition IN ('000-009', '000') ORDER BY pageTreePosition DESC
0.3143  0.0003  [7] Using template: /templates/navigation/item.html
0.3161  0.0018  [8] SELECT regionKey, regionHTML FROM perch2_content_regions WHERE regionPage='/reveiws.php' OR regionPage='*' ORDER BY regionPage DESC
0.3164  0.0004  [1] SELECT regionID, regionTemplate, regionPage, regionRev AS rev FROM perch2_content_regions WHERE regionKey='Social Media' AND (regionPage='/reveiws.php' OR regionPage='*')
0.3167  0.0002  [1] SELECT * FROM ( SELECT idx.itemID, c.regionID, idx.pageID, c.itemJSON, idx2.indexValue as sortval FROM perch2_content_index idx JOIN perch2_content_items c ON idx.itemID=c.itemID AND idx.itemRev=c.itemRev AND idx.regionID=c.regionID JOIN perch2_content_index idx2 ON idx.itemID=idx2.itemID AND idx.itemRev=idx2.itemRev AND idx2.indexKey='_order' WHERE ((idx.regionID=92 AND idx.itemRev=8)) AND idx.itemID=idx2.itemID AND idx.itemRev=idx2.itemRev ) as tbl GROUP BY itemID, pageID, itemJSON, sortval ORDER BY sortval ASC
0.3267  0.01    [1] Using template: /templates/content/phone.html
0.3272  0.0005  [1] SELECT regionID, regionTemplate, regionPage, regionRev AS rev FROM perch2_content_regions WHERE regionKey='Reservation Links' AND (regionPage='/reveiws.php' OR regionPage='*')
0.3275  0.0003  [1] SELECT * FROM ( SELECT idx.itemID, c.regionID, idx.pageID, c.itemJSON, idx2.indexValue as sortval FROM perch2_content_index idx JOIN perch2_content_items c ON idx.itemID=c.itemID AND idx.itemRev=c.itemRev AND idx.regionID=c.regionID JOIN perch2_content_index idx2 ON idx.itemID=idx2.itemID AND idx.itemRev=idx2.itemRev AND idx2.indexKey='_order' WHERE ((idx.regionID=103 AND idx.itemRev=10)) AND idx.itemID=idx2.itemID AND idx.itemRev=idx2.itemRev ) as tbl GROUP BY itemID, pageID, itemJSON, sortval ORDER BY sortval ASC
0.3296  0.0021  [1] Using template: /templates/content/reservation_links.html
0.3311  0.0015  [nil] SELECT * FROM perch2_comments WHERE 1=1 AND parentID='general' AND commentStatus='LIVE' ORDER BY commentDateTime ASC
0.3316  0.0006  [] Using template: /templates/comments/comment.html