I am trying to:
Build review module using CRED.
I have read the following topics:
https://toolset.com/forums/topic/how-to-get-rating-average-from-cred-for-review/
https://toolset.com/forums/topic/review-system-how-to-get-average-rating/
https://toolset.com/forums/topic/creating-star-select-with-cred-radio-form/
https://toolset.com/forums/topic/apply-css-to-types-radio-fields/
I'm trying to accomplish review system using above reference using HTML and CSS according to this tutorial: hidden link
So far so good, however, on CRED form after submitted the input value does not save/pass to database.
I visited this URL:
I expected to see:
To see new average rating
Instead, I got:
I see one new review but average rating stay the same.
My CRED Code
[credform class="cred-form cred-keep-original"]
<h2>Your are Reviewing: [cred-post-parent get='title']</h2>
<a href="[cred-post-parent get='url']">Back to [cred-post-parent get='title']</a>
<div class="cred-field cred-field-post_title">
<label class="cred-label">
Your Review Title
</label>
[cred_field field="post_title" post="reviews" value="" urlparam=""]
</div>
<div class="cred-group cred-group-Ratings">
<div class="cred-header"><h3>Ratings</h3></div>
<div class="cred-field cred-field-ratings">
<label class="cred-label">
Overall Ratings
</label>
<div>
<input class="star star-5" id="star-5" type="radio" name="wpcf-ratings" value="5" data-types-value="5" data-wpt-name="wpcf-ratings" title="Outstanding"/>
<label class="star star-5" for="star-5"></label>
<input class="star star-4" id="star-4" type="radio" name="wpcf-ratings" value="4" data-types-value="4" data-wpt-name="wpcf-ratings" title="Very Good"/>
<label class="star star-4" for="star-4"></label>
<input class="star star-3" id="star-3" type="radio" name="wpcf-ratings" value="3" data-types-value="3" data-wpt-name="wpcf-ratings" title="Good"/>
<label class="star star-3" for="star-3"></label>
<input class="star star-2" id="star-2" type="radio" name="wpcf-ratings" value="2" data-types-value="2" data-wpt-name="wpcf-ratings" title="Poor"/>
<label class="star star-2" for="star-2"></label>
<input class="star star-1" id="star-1" type="radio" name="wpcf-ratings" value="1" data-types-value="1" data-wpt-name="wpcf-ratings" title="Very Poor"/>
<label class="star star-1" for="star-1"></label>
</div>
</div><br /><br />
<div class="cred-field cred-field-reviews">
<label class="cred-label">
Reviews
</label>
[cred_field field="reviews" post="reviews" value="" urlparam=""]
</div>
</div>
[cred_field field="form_submit" value="Submit" urlparam=""]
[/credform]
My CSS
div.stars {
width: 270px;
display: inline-block;
}
input.star { display: none; float: right; }
label.star {
float: right;
padding: 10px;
font-size: 36px;
color: #444;
transition: all .2s;
}
input.star:checked ~ label.star:before {
content: '\f005';
color: #FD4;
transition: all .25s;
}
input.star-5:checked ~ label.star:before {
color: #FE7;
text-shadow: 0 0 20px #952;
}
input.star-1:checked ~ label.star:before { color: #F62; }
label.star:hover { transform: rotate(-15deg) scale(1.3); }
label.star:before {
content: '\f006';
font-family: FontAwesome;
}
Waiting for your respond 🙂
Thanks,
JSon
Luo Yang
Supporter
Languages:
Inglés (English )
Chino simplificado (简体中文 )
Timezone:
Asia/Hong_Kong (GMT+08:00)
Dear JSon,
You are using static HTML codes to setup the radio field "wpcf-ratings",
I suggest you try CRED action hook cred_save_data to save it into database, for example, add below codes in your theme/functions.php:
add_action('cred_save_data', 'my_save_data_action',10,2);
function my_save_data_action($post_id, $form_data)
{
// if a specific form
if ($form_data['id']==123)
{
if (isset($_POST['wpcf-ratings']))
{
// add it to saved post meta
add_post_meta($post_id, 'wpcf-ratings', $_POST['wpcf-ratings']);
}
}
}
Please replace 123 with your CRED form post ID
More help:
https://toolset.com/documentation/user-guides/cred-api/#csd
Sorry for late reply. I was on vacation 🙂
Thank you so much Luoy. You did it again, excellent support.
thumb up!
cheers 🙂