Forum

Thread tagged as: Question

Adding star rating in perch comment app

I want to add star rating on my comment app. But how can I output into comment page?

My comment_form.html

<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="rating_list">
            <p>
            <perch:input class="with-gap" name="group3" type="radio" id="test5" value="5" checked />
            <perch:label for="test5">5</perch:label>
            <i class="material-icons">star</i>
            <i class="material-icons">star</i>
            <i class="material-icons">star</i>
            <i class="material-icons">star</i>
            <i class="material-icons">star</i>
            </p>
            <p>
            <perch:input class="with-gap" name="group3" type="radio" id="test4" value="4" />
            <label for="test4">4</label>
            <i class="material-icons">star</i>
            <i class="material-icons">star</i>
            <i class="material-icons">star</i>
            <i class="material-icons">star</i>
            </p>
</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>

comment.html

<perch:before>
    <h2>Comments</h2>
    <ul class="comments listing">
</perch:before>
        <li id="comment<perch:comments id="commentID" type="hidden" />">
            <img src="//www.gravatar.com/avatar/<perch:comments id="commentEmail" type="email" label="Email" order="2" hash="md5" required="true" />?s=120&d=mm" width="60" height="60" />

            <div class="comment">
                <div class="commenter">
            <perch:if exists="test5">
            <perch:comments name="group3" id="test5" value="5" label="5 star" />
            <i class="material-icons">star</i>
            <i class="material-icons">star</i>
            <i class="material-icons">star</i>
            <i class="material-icons">star</i>
            <i class="material-icons">star</i>
            </perch:if>

  <perch:showall />
                </div>
                <p rel="bookmark" class="date"><perch:comments id="commentDateTime" format="%d %b %Y %X" type="date" time="true" label="Date" /></p>

                <perch:comments id="commentHTML" encode="false" html="true" type="textarea" label="Message (HTML)" order="4" required="true" />
            </div>
        </li>
<perch:after>
    </ul>
</perch:after>

Diagnostics

Perch Runway: 3.0.14
Production mode: Development (10)
Installed apps: content (3.0.14), assets (3.0.14), categories (3.0.14), perch_comments (1.2.1)
DB driver: PDO
DB tables: perch3_backup_plans (0), perch3_backup_resources (0), perch3_backup_runs (0), perch3_categories (0), perch3_category_counts (0), perch3_category_sets (0), perch3_collection_index (0), perch3_collection_items (0), perch3_collection_revisions (0), perch3_collections (0), perch3_comments (3), perch3_comments_votes (0), perch3_content_index (1044), perch3_content_items (80), perch3_content_locks (0), perch3_content_regions (12), perch3_menu_items (9), perch3_navigation (0), perch3_navigation_pages (0), perch3_page_routes (0), perch3_page_templates (9), perch3_pages (6), perch3_resource_log (1153), perch3_resource_tags (0), perch3_resources (270), perch3_resources_to_tags (0), perch3_settings (23), perch3_user_passwords (0), perch3_user_privileges (31), perch3_user_role_buckets (0), perch3_user_role_privileges (2), perch3_user_roles (2), perch3_users (1)
Users: 1
App runtimes:
<?php
    $apps_list = array(
        'perch_comments',

    );
?>
Scheduled tasks for perch_comments: delete_spam_comments (1440 mins)
Editor plug-ins:
H1: fcaff1308dee356f3127acd5bfabdd7b
L1: 696f824b0a12ded600a38ed45eaee28a
F1: 3b606135b33e6a102526838f4152a807
headerColour: #000000
content_singlePageEdit: 1
helpURL:
siteURL: /
hideBranding: 1
content_collapseList: 1
lang: en-gb
installedAt: 3.0.13
update_3.0.13: done
update_runway_3.0.14: done
headerScheme: dark
update_runway_3.0.13: done
latest_version:
on_sale_version:
dashboard: 0
sidebar_back_link: 1
hide_pwd_reset: 0
keyboardShortcuts: 0
siteOffline: 0
content_hideNonEditableRegions: 1
content_frontend_edit: 0
content_skip_region_list: 0
assets_restrict_buckets: 1
PERCH_DEVELOPMENT: 10
PERCH_STAGING: 50
PERCH_PRODUCTION: 100
PERCH_SITEPATH: /var/www/vhosts/httpdocs
PERCH_SCHEDULE_SECRET: YcvVU6cow2ybREkf
PERCH_DB_USERNAME: dummy
PERCH_DB_SERVER: localhost
PERCH_DB_DATABASE: dummy_
PERCH_DB_PREFIX: perch3_
PERCH_EMAIL_FROM: email
PERCH_EMAIL_FROM_NAME: name
PERCH_LOGINPATH: /perch
PERCH_PATH: /var/www/vhosts/mydomain.com/httpdocs/perch
PERCH_CORE: /var/www/vhosts/mydomain.com/httpdocs/perch/core
PERCH_RESFILEPATH: /var/www/vhosts/mydomain.com/httpdocs/perch/resources
PERCH_RESPATH: /perch/resources
PERCH_RWD: 1
PERCH_HTML5: 1
PERCH_TZ: UTC
PERCH_PRODUCTION_MODE: 10
PERCH_SITE_BEHIND_LOGIN: 1
PERCH_DEBUG: 1
PERCH_RUNWAY: 1
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_ASSET_VERSION: f704e7442d11292c99b5
PERCH_PREVIEW_ARG: preview
PERCH_TEMPLATE_PATH: /var/www/vhosts/mydomain.com/httpdocs/perch/templates
PERCH_TEMPLATE_FILTERS:
PERCH_DEFAULT_DOC: index.php
PERCH_DEFAULT_EXT: .php
PERCH_XHTML_MARKUP:
PERCH_HTML_ENTITIES:
PERCH_SSL:
PERCH_STRIPSLASHES:
PERCH_PROGRESSIVE_FLUSH: 1
PERCH_PARANOID:
PERCH_FORCE_SECURE_COOKIES:
PERCH_DEFAULT_BUCKET: default
PERCH_TRANSLATION_ASSIST:
PERCH_PASSWORD_MIN_LENGTH: 6
PERCH_MAX_FAILED_LOGINS: 10
PERCH_AUTH_LOCKOUT_DURATION: 1 HOUR
PERCH_VERIFY_UPLOADS:
PERCH_PRIV_ASSIST:
PERCH_CUSTOM_EDITOR_CONFIGS:
PERCH_ENABLE_EXIF: 1
PERCH_AUTH_PLUGIN:
PERCH_DB_CHARSET: utf8
PERCH_DB_PORT:
PERCH_DB_SOCKET:
PERCH_APPS_EDITOR_PLUGIN: markitup
PERCH_APPS_EDITOR_MARKUP_LANGUAGE: markdown
Hosting settings
PHP: 7.1.14
Zend: 3.1.0
OS: Linux
SAPI: cgi-fcgi
Safe mode: not detected
MySQL client: mysqlnd 5.0.12-dev - 20150407 - $Id: 38fea24f2847fa7519001be390c98ae0acafe387 $
MySQL server: 5.5.55
Free disk space: 269.99 GB
Extensions: Core, date, libxml, openssl, pcre, zlib, bz2, calendar, ctype, hash, filter, ftp, gettext, gmp, SPL, iconv, pcntl, readline, Reflection, session, standard, SimpleXML, sockets, mbstring, tokenizer, xml, cgi-fcgi, mysqlnd, bcmath, curl, dba, dom, enchant, fileinfo, gd, imagick, imap, intl, json, ldap, exif, mcrypt, mysqli, odbc, PDO, pdo_mysql, PDO_ODBC, pdo_pgsql, pdo_sqlite, pgsql, Phar, posix, pspell, redis, soap, sqlite3, sysvmsg, sysvsem, sysvshm, tidy, xmlreader, xmlrpc, xmlwriter, xsl, zip, ionCube Loader, Zend OPcache
GD: Yes
ImageMagick: Yes
PHP max upload size: 128M
PHP max form post size: 128M
PHP memory limit: 128M
Total max uploadable file size: 128M
Resource folder writeable: Yes
Session timeout: 24 minutes
Native JSON: Yes
Filter functions: Yes
Transliteration functions: Yes
PATH: /sbin:/usr/sbin:/bin:/usr/bin
PP_CUSTOM_PHP_INI: /var/www/vhosts/system/mydomain.com/etc/php.ini
PP_CUSTOM_PHP_CGI_INDEX: plesk-php71-fastcgi
SCRIPT_NAME: /perch/core/settings/diagnostics/index.php
REQUEST_URI: /perch/core/settings/diagnostics/?extended
QUERY_STRING: extended
REQUEST_METHOD: GET
SERVER_PROTOCOL: HTTP/1.0
GATEWAY_INTERFACE: CGI/1.1
REMOTE_PORT: 37062
SCRIPT_FILENAME: /var/www/vhosts/mydomain.com/httpdocs/perch/core/settings/diagnostics/index.php
SERVER_ADMIN: eduardo@detoxstudio.com
DOCUMENT_ROOT: /var/www/vhosts/mydomain.com/httpdocs
REMOTE_ADDR: 82.2.78.216
SERVER_PORT: 443
SERVER_ADDR: 46.32.228.185
SERVER_NAME: mydomain.com
SERVER_SOFTWARE: Apache
SERVER_SIGNATURE: <address>Apache Server at mydomain.com Port 443</address>
HTTP_COOKIE: PHPSESSID=gqdesdh09u4gtcfg7q4846eju9; cmsa=1
HTTP_ACCEPT_LANGUAGE: en-GB,en-US;q=0.9,en;q=0.8
HTTP_ACCEPT_ENCODING: gzip, deflate, br
HTTP_REFERER: https://mydomain.com/perch/core/settings/diagnostics/
HTTP_ACCEPT: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8
HTTP_USER_AGENT: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36
HTTP_UPGRADE_INSECURE_REQUESTS: 1
HTTP_CONNECTION: close
HTTP_X_ACCEL_INTERNAL: /internal-nginx-static-location
HTTP_X_FORWARDED_FOR: IP here
HTTP_X_REAL_IP: IP here
HTTP_HOST: mydomain.com
HTTPS: on
SCRIPT_URI: https://mydomain.com/perch/core/settings/diagnostics/
SCRIPT_URL: /perch/core/settings/diagnostics/
UNIQUE_ID: Wo-g-X8AAAEAADIUdM8AAAAA
FCGI_ROLE: RESPONDER
PHP_SELF: /perch/core/settings/diagnostics/index.php
REQUEST_TIME_FLOAT: 1519378685.1782
REQUEST_TIME: 1519378685
Edward Johansen

Edward Johansen 0 points

  • 3 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

What problem are you seeing?

The comment html is showing, but not the star chosen rating.

But not this one below:

<perch:if exists="test5">
<perch:comments name="group3" id="test5" value="5" label="5 star" />
<i class="material-icons">star</i>
<i class="material-icons">star</i>
<i class="material-icons">star</i>
<i class="material-icons">star</i>
<i class="material-icons">star</i>
</perch:if>

There is not error in debug

Drew McLellan

Drew McLellan 2638 points
Perch Support

Do you see it in perch:showall ?

Yes, I can see the value.

Brackets removed as it causes problem in this forum

ID  Value
perch_page_path /destinations/bohol
group3  4
submitComment   Submit
commentID   86
parentID    subpages
parentTitle Destinations
commentScore    0
commentName Edward
commentEmail    xxxx@hotmail.com
commentURL  
commentIP   xxxxxx
commentDateTime 2018-02-23 10:43:37
commentHTML 
aserdsret drt drt
commentStatus   LIVE
commentSpamData "fields":"name":"xxx","email":"xxmail","body":"aserdsret drt...
commentDynamicFields    "group3":"4","submitComment":"Submit"
perch_group3    4
perch_submitComment Submit
paging  false
total   2
number_of_pages 1
total_pages 1
per_page    0
current_page    1
lower_bound 1
upper_bound 0
prev_url    
next_url    
prev_page_number    
next_page_number    
first_page_url  /destinations/bohol
last_page_url   /destinations/bohol
first_page  true
last_page   true
perch_item_last true
perch_item_zero_index   1
perch_item_index    2
perch_item_rev_index    1
perch_item_rev_zero_index   0
perch_item_odd  odd
perch_item_count    2
perch_index_in_set  2
perch_zero_index_in_set 1
perch_last_in_set   true
perch_namespace perch:comments
Drew McLellan

Drew McLellan 2638 points
Perch Support

You're testing for exists="test5" but your field is called group3.

Perhaps giving the field a more descriptive name would help the confusion.

The group is for Materialize input.

Anyway, I change the template of comment_form.html. How to output the value of the one below into comment.html using conditional value?

<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>

I tried this in my comment.html. But it is not showing in the comment page.


<perch:if exists="ratingStar5"> <perch:comments id="ratingStar5" label="5star" required="false" name="rating" value="5" /> </perch:if>
Drew McLellan

Drew McLellan 2638 points
Perch Support

Do you still see it in perch:showall ?

Yes.

ID  Value
perch_page_path /destinations/bohol
rating  5
submitComment   Submit
commentID   112
parentID    subpages
parentTitle Destinations
commentScore    0
commentName Edward
commentEmail    mymail@hotmail.com
commentURL  
commentIP   1375882968
commentDateTime 2018-02-23 14:36:14
commentHTML 
test

commentStatus   LIVE
commentSpamData "fields":"name":"Edward","email":"mymail@hotmail.com","body":"test","environment":"PATH":"\/sbin...
commentDynamicFields    "rating":"5","submitComment":"Submit"
perch_rating    5
perch_submitComment Submit
paging  false
total   2
number_of_pages 1
total_pages 1
per_page    0
current_page    1
lower_bound 1
upper_bound 0
prev_url    
next_url    
prev_page_number    
next_page_number    
first_page_url  /destinations/bohol
last_page_url   /destinations/bohol
first_page  true
last_page   true
perch_item_last true
perch_item_zero_index   1
perch_item_index    2
perch_item_rev_index    1
perch_item_rev_zero_index   0
perch_item_odd  odd
perch_item_count    2
perch_index_in_set  2
perch_zero_index_in_set 1
perch_last_in_set   true
perch_namespace perch:comments

Fine, I got it working.

          <perch:if id="rating" value="5">
              <perch:comments id="ratingStar5" label="5star" required="false" name="rating" value="5" />
              5 Stars
          </perch:if>

          <perch:if id="rating" value="1">
              <perch:comments id="ratingStar1" label="1star" required="false" name="rating" value="1" />
              1 star
          </perch:if>