Hello,
I’ve bought the Ratings module from Mitchell and am now sitting here completely clueless concerning the implementation of this module.
What I’m trying to accomplish is fairly simple.
I’d like to insert a star rating option to weblog entries. No reviews, just the ratings as can be seen on e.g. Stylegala and the like. Basically, just for a user to see the stars, click on stars 1-5 and then be over and done.
I’d be happy if I actually knew how to start. :( I’ve read the docs at solspace but understand zero, nada. :(
If anyone could give me any pointers, I’d be extremely grateful.
Thanks
maleika
Edit:
Here is some example code that does not work (probably wrong implementation):
{exp:weblog:entries limit="1" orderby_ratings="desc" rdf="off" disable="member_data|trackbacks"}
<h2 id="latest-news"><span>{title}</span></h2>
{exp:rating:form entry_id="{entry_id}" form_name="review" require_membership="yes" admin_template="admin_template" anonymous="yes" status="open" return="{path=’rating/thanks’}"}
<input type="hidden" name="name" value="{screen_name}" />
<input type="hidden" name="email" value="{email}" />
<label for="review">Your Rating</label>
<select name="rating">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
</select>
{/exp:rating:form}
<!-- Begin News Summaries -->
<div id="vendor">
{vendor_photo}
<dl>
<dt>{title}</dt>
{categories parent_only="yes"}
<dd>Category: <a href="http://{path=">{category_name},</a></dd>
{/categories}
<dd>State: {vendor_state}</dd>
<dd>City: {vendor_city}</dd>
<dd>Homepage: {vendor_url}</dd>
</dl>
<!-- End News Summaries -->
<div id="vendor-description">
{vendor_description}
</div>
</div>
{/exp:weblog:entries}
I have also just purchased the ratings plugin and have had a couple of issues.
1) The install readme for the extensions is wrong. See the correct one attached. 2) There was also a bug in the mcp.rating.php file. I don’t want to post it here but if you email solspace they should send you a new file asap.
After those issues where solved this is my current implementation of the ratings system:
{exp:weblog:entries weblog="your_weblog" limit="15"}
{title}
{exp:rating:form entry_id="{entry_id}" form_name="your_form_name"}
<input type="hidden" name="name" value="{screen_name}" />
<input type="hidden" name="email" value="{email}" />
<label for="review">Your Rating</label>
<select name="rating">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
</select>
<input type="submit" value="submit">
{/exp:rating:form}
{exp:rating:stats entry_id="{entry_id}" theme="default"}{stars_overall_avg}
Based on {overall_count} review{if overall_count != "1"}s{/if}
{/exp:rating:stats}
{/exp:weblog:entries}
Ill post more on this as I figure it out.
Thank you both for being some of the first users of the Rating module 2.0. No doubt that it is a complex module. I built for power rather than ease of use. I’m sorry if it is confusing.
From what I see above, you guys have valid rating forms. Are they breaking?
And Leevi, thank you for noting the bugs and the read me file. I have just posted Rating 2.0.5 which includes the corrected read me file as well as adds the ability to declare a class for your rating form.
Leevi, you asked about getting help with some AJAX functions and the Rating module. How may I help you? What sorts of things are you trying to do? And I salute you both for wading into the deep water that is AJAX!! ha ha
mk
@MK: Thanks for your help so far. I think the biggest confusion comes from not knowing whih ratings tags go in which templates.
Can the form tag be used on a page that lists multiple entries of a weblog? If so is there some way to have unique IDs on each form. Eg: If your weblog shortname is “news” the open form tag would be:
<form id='news' name='news' method="post" action="http://provirb.dev/news/">
it would be great if the form is used multiple times on one page to have unique (or even custom) ids on the form. eg:
<form id='news-1' name='news' method="post" action="http://provirb.dev/news/">
or
<form id='my_custom_id' name='news' method="post" action="http://provirb.dev/news/">
Can you provide a sample form tag that includes the template parameter? My current form now looks like:
{exp:rating:form entry_id="{entry_id}" form_name="profiles" template="ratings/thankyou" }
<input type="hidden" name="name" value="{screen_name}" />
<input type="hidden" name="email" value="{email}" />
<label for="review">Your Rating</label>
<select name="rating">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
</select>
<input type="submit" value="submit">
{/exp:rating:form}
Which submits via AJAX. The return template “ratings/thankyou” looks like:
{if success}success{/if}
{if failure}failure{/if}
{message}
however I am getting the following template loop error:
"If you your response template contains the wrong type of exp:rating tag you will create a template loop that will choke your site. Make sure you haven't done this."
A brief example of what tags can go in which templates would be great!
Leevi,
Everythng you’re doing looks right so far. Here are some specifics.
I often have the rating form created inside a weblog:entries loop. I pass the form_name= parameter and populate it with something like form_name=”rating{entry_id}”. This generates an ID for the form with that name. But also note that if you do not provide the form_name parameter, the module will automatically give an id to the form of “rating_form78” where 78 is the entry id that was passed to the form in the ‘entry_id’ parameter.
Your thank you template, I think, likely has something like exp:rating:form or something. Nothing is necessary in that template but the message variable and the conditionals. You don’t indicate that you have a module call in that template, but just confirm that for me.
Lastly, AJAX is tricky. I always have a bit of trouble with it. Especially in this context.
Let me know if this helps at all.
mk
Ok heres where I am at the moment.
Installed the new version (2.0.5) of the module and upgraded without issue. Added class names to all my forms using the class param in the ratings:form tag.
The following form returns the standard “Success You rating has been successfully submitted.” if it is submitted with or without AJAX as expected.
{exp:weblog:entries weblog="profiles" limit="15"}
{title}
{exp:rating:form entry_id="{entry_id}" class="profile-rating-form" form_name="profiles_{entry_id}"}
<input type="hidden" name="name" value="{screen_name}" />
<input type="hidden" name="email" value="{email}" />
<label for="review">Your Rating</label>
<select name="rating">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
</select>
<input type="submit" value="submit">
{/exp:rating:form}
{exp:rating:stats entry_id="{entry_id}" theme="default"}
{stars_overall_avg}
Based on {overall_count} review{if overall_count != "1"}s{/if}
{/exp:rating:stats}
{/exp:weblog:entries}
Both the traditional and AJAX submits are directed to: http://provirb.dev/index.php?/profiles/leevi/ which is the same url as where the form is displayed.
The form above renders the following html:
<form class="profile-rating-form" id='profiles_3' name='profiles_3' method="post" action="http://provirb.dev/index.php?/profiles/leevi/" >
<div>
<input type="hidden" name="ACT" value="20" />
<input type="hidden" name="RET" value="http://provirb.dev/index.php?/profiles/leevi/" />
<input type="hidden" name="URI" value="/profiles/leevi/" />
<input type="hidden" name="PRV" value="" />
<input type="hidden" name="XID" value="535f84a0eba6d201c78017b1b74673905a533635" />
<input type="hidden" name="entry_id" value="3" />
<input type="hidden" name="form_name" value="profiles_3" />
<input type="hidden" name="status" value="open" />
<input type="hidden" name="anonymous" value="n" />
<input type="hidden" name="user_template" value="" />
<input type="hidden" name="admin_template" value="" />
</div>
<input type="hidden" name="name" value="Leevi Graham" />
<input type="hidden" name="email" value="info@leevigraham.com" />
<label for="review">Your Rating</label>
<select name="rating">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
</select>
<input type="submit" value="submit">
</form>
All good so far. The issue starts when I the template parameter:
template="ratings/thankyou"
Both the normal submit and the AJAX submit return the template_loop error.
The ratings/thankyou template contains:
{if success}success{/if}
{if failure}failure{/if}
{message}
with no other code.
One other request.
It would still be great to have the ability to separate the html form id parameter and the ratings:form form_name parameter.
This would reduce the amount of forms displayed in the admin. For example if there are 1000 entries in the profile weblog I would not want 1000 forms in the admin.
Correct me if I’m wrong but in the admin when you click on the form name to Manage Entries each form can have many different entries which means you don’t need 1000 different forms.
Excellent news regarding the form IDs.
Currently I am testing the form functionality on my local machine but I plan to upload a temporary splash page to my new site tonight and I will email you with access to the admin once that has been completed.
Thanks for your help so far
Success!
The possible combination of one of the following has allowed me to move forward.
Setup
I am running ExpressionEngine 1.5.2 (build 20070302) on Dreamhost.
Force URL Query strings is off.
My .htaccess file looks like
RewriteEngine on
RewriteCond $1 ^(profiles|P[0-9]{2,8})
RewriteRule ^(.*)$ /index.php?/$1 [L]
This allows me to use the following url structure: http://mysite.com/my_template_group/my_template
jQuery and the jQuery Form Plugin are used to submit the form via AJAX
Template Group and Templates
I have one template group named “profiles”
The profiles template group has two templates “index” and “rating_ajax_return”
The “index” template looks like:
{embed="_includes/head_meta"}
{embed="_includes/header"}
// <![CDATA[
$(document).ready(function() {
var options = { success: showResponse };
$(".profile-rating-form").submit(function() {
$(this).ajaxSubmit(options);
return false;
});
});
function showResponse(responseText, statusText) {
alert(responseText)
}
// ]]>
</script>
{exp:weblog:entries weblog="profiles" limit="15"}
{title}
{exp:rating:form entry_id="{entry_id}"
form_id ="profile-rating-{entry_id}"
class="profile-rating-form"
form_name="profiles"
template="profiles/rating_ajax_return"
}
<input type="hidden" name="name" value="{screen_name}" />
<input type="hidden" name="email" value="{email}" />
<label for="review">Your Rating</label>
<select name="rating">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
</select>
<input type="submit" value="submit">
{/exp:rating:form}
{exp:rating:stats entry_id="{entry_id}" theme="default"}
{stars_overall_avg}
Based on {overall_count} review{if overall_count != "1"}s{/if}
{/exp:rating:stats}
{/exp:weblog:entries}
{embed="_includes/_foot"}
Which renders the following form:
// only form code pasted..
<form class="profile-rating-form" id='profile-rating-2' name='profiles' method="post" action="http://mysite.com/profiles/index/" >
<div>
<input type="hidden" name="ACT" value="20" />
<input type="hidden" name="RET" value="http://mysite.com/profiles/index/" />
<input type="hidden" name="URI" value="/profiles/index/" />
<input type="hidden" name="PRV" value="" />
<input type="hidden" name="XID" value="b62be42e5a7b56d55980f690f28c12d6c26b8c5e" />
<input type="hidden" name="entry_id" value="2" />
<input type="hidden" name="form_name" value="profiles" />
<input type="hidden" name="status" value="open" />
<input type="hidden" name="anonymous" value="n" />
<input type="hidden" name="user_template" value="" />
<input type="hidden" name="admin_template" value="" />
<input type="hidden" name="template" value="profiles/rating_ajax_return" />
</div>
<input type="hidden" name="name" value="Leevi Graham" />
<input type="hidden" name="email" value="info@leevigraham.com" />
<label for="review">Your Rating</label>
<select name="rating">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
</select>
<input type="submit" value="submit">
</form>
Each form has a unique id the same class name and results are grouped in the admin under the “profiles” form name.
There is no return param as the form is being submitted by AJAX. It is also important to note that the jQuery scripts are loaded in the _includes/meta_head template, don’t forget those bad boys.
The return template is named “rating_ajax_return” and is located in the “profiles” template group.
The “rating_ajax_return” template is simple and contains only the following three lines:
{if success}success{/if}
{if failure}failure{/if}
{message}
Thats my basic setup so far.
So now for my wishlist of features that would really make this a killer plugin.
The one thing that I think should be included is the ability to return the updated rating/review in the ajax call rather than just a message. Currently I think I will need to create a new template that just has a single rating in it, use an ajax get request and return the template html after the user has submitted their rating. This means an extra ajax request.
It would be great if a user submitted their rating with AJAX and then was presented the new rating inplace of the old form.
The one other thing (which may already be implemented) is to log which user has added a rating review previously and no allow them to add another.
Thanks mk for your great work so far.
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.