Raymond Geerts Posted June 4, 2015 Share Posted June 4, 2015 FieldtypeStarRating Module for ProcessWire - Field that stores an integer by using a star rating interface. Current version: 1.0.0 Module page: http://modules.processwire.com/modules/fieldtype-star-rating/ Github: https://github.com/Rayden/FieldtypeStarRating To install Copy to /site/modules/ and go to Admin > Modules > Check for new modules. Tested on ProcessWire 2.6.2 dev Usage back-end Create a new field with the fieldtype Star Rating. Set the amount of stars you want to show, by default it is set to 5 stars. Assign the field to any template. Now you can set the field value by selecting any of the 5 stars. The number saved to the database equals the number of stars that are highlighted. Hovering the stars will show a reset icon, which will reset the value to 0 by clicking on it. 14 Link to comment Share on other sites More sharing options...
netcarver Posted June 4, 2015 Share Posted June 4, 2015 Very, very nice. Thank you! Is this in the module directory yet? 1 Link to comment Share on other sites More sharing options...
Raymond Geerts Posted June 4, 2015 Author Share Posted June 4, 2015 I just added it to the module directory. Also did a tiny modification in one of the selectors in the javascript file. Link to comment Share on other sites More sharing options...
bernhard Posted June 14, 2015 Share Posted June 14, 2015 looks very nice! like albert asked on the module page i would also be curious if this module is only thought to be used in the backend? 1 Link to comment Share on other sites More sharing options...
Raymond Geerts Posted June 15, 2015 Author Share Posted June 15, 2015 As requested an example on how to output the star rating on the front-end. This one is based on Font Awesome, but you can adept this to any font or even plain images if you prefer. <?php /** * Small example output for FieldtypeStarRating on the front-end * */ ?> <!DOCTYPE html> <html lang="en"> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <title><?php echo $page->title; ?></title> <link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css"> <style> .star { color: #d9d9d9; } .star.selected { color: #FFAE00; } </style> </head> <body> <h1><?php echo $page->title; ?></h1> <span> <?php $star_count = $fields->star_rating_field->star_count; for ($i = 1; $i <= $star_count; $i++) { if ($i <= $page->star_rating_field) { echo "<span class='fa fa-star star selected'></span>"; } else { echo "<span class='fa fa-star star'></span>"; } } ?> </span> <?php if($page->editable()) echo "<p><a href='$page->editURL'>Edit</a></p>"; ?> </body> </html> 1 Link to comment Share on other sites More sharing options...
bernhard Posted June 15, 2015 Share Posted June 15, 2015 thank you raymond, so it looks like there is no javascript/ajax magic built in like it is for example in the comments fieldtype. that would be awesome - although i have no need for either your current version or with ajax voting 1 Link to comment Share on other sites More sharing options...
Raymond Geerts Posted June 16, 2015 Author Share Posted June 16, 2015 This module is merely intended for a visual gui on back-end level to store and output an integer. When you need (star) rating / voting on front-end the following module might fit your needs better: http://modules.processwire.com/modules/page-ratings/ Link to comment Share on other sites More sharing options...
mr-fan Posted June 16, 2015 Share Posted June 16, 2015 since it is a Inputfield it should be possible to use it with the API on a own form -right? $field = $modules->get("InputfieldStarRating"); regards mr-fan 2 Link to comment Share on other sites More sharing options...
MilenKo Posted March 9, 2017 Share Posted March 9, 2017 Hello. As far as my coding skills allows to understand, the example from Raymond Geerts would make the star number to appear rather then allow the user/visitors to rate a page content. Does anyone have implemented similar functionality for the frontend using FieldTypeStarRating? Link to comment Share on other sites More sharing options...
rareyush Posted April 6, 2018 Share Posted April 6, 2018 $rating = $item->rating; for ($i = 1; $i <= $rating; $i++) { if ($i <= $page->rating) { $rate = "<span class='fa fa-star star selected '> </span>"; } else { $rate = "<span class='fa fa-star'> </span>"; } } I am using this and and I can see only 1 star everywhere, where i am wrong??? Link to comment Share on other sites More sharing options...
Gary Austin Posted April 6, 2018 Share Posted April 6, 2018 8 minutes ago, rareyush said: $rating = $item->rating; for ($i = 1; $i <= $rating; $i++) { if ($i <= $page->rating) { $rate = "<span class='fa fa-star star selected '> </span>"; } else { $rate = "<span class='fa fa-star'> </span>"; } } I am using this and and I can see only 1 star everywhere, where i am wrong??? Assuming $rate is the final string you will output later, you need to set $rate="" before loop and use $rate .= "<sp...." in the loops. the '.=' is the key. 2 Link to comment Share on other sites More sharing options...
rareyush Posted April 6, 2018 Share Posted April 6, 2018 1 hour ago, Gary Austin said: Assuming $rate is the final string you will output later, you need to set $rate="" before loop and use $rate .= "<sp...." in the loops. the '.=' is the key. thanks it worked. Link to comment Share on other sites More sharing options...
BenSlayers Posted October 28, 2019 Share Posted October 28, 2019 (edited) Hello, I've used this module on a few sites in the past but recently tried using it inside a repeater (to reduce the number of unnecessary pages) and I'm having an issue. If I add a new repeater item, I can't select the rating until I save the page. I can see the stars when I hover but if I select a rating, it just goes back to the greyed-out stars. Is there a quick fix for this? I wasn't sure if this issue was only happening with my installation but I just tried it on another website and had the exact same problem. All suggestions are welcome - thanks! Edit: I've also noticed that once I have set the value of the star rating inside my repeater item and save the page, if I try to go back in and change the value, it won't let me. Edited October 28, 2019 by Ben Sayers More details regarding the issue Link to comment Share on other sites More sharing options...
Robin S Posted October 29, 2019 Share Posted October 29, 2019 On 10/29/2019 at 7:15 AM, Ben Sayers said: Hello, I've used this module on a few sites in the past but recently tried using it inside a repeater (to reduce the number of unnecessary pages) and I'm having an issue. @Ben Sayers, I created a pull request with a fix for this issue: https://github.com/Rayden/FieldtypeStarRating/pull/1 In the meantime you could update InputfieldStarRating.js with the code from here and do a hard refresh in your browser to clear the cache. 1 Link to comment Share on other sites More sharing options...
BenSlayers Posted October 30, 2019 Share Posted October 30, 2019 6 hours ago, Robin S said: In the meantime you could update InputfieldStarRating.js with the code from here and do a hard refresh in your browser to clear the cache. Thanks @Robin S, that did the trick! Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now