Submitting a review
To submit a review, you can make a post request to product-review/review/save action endpoint.
A review must already exist before it can be submitted. The plugin creates them when an order reaches your configured status, and currentUser.getWaitingToReviewItems() lists the ones waiting.
Params
id
Required. The ID of the review that will be saved.
rating
Required. The rating value for the product, a whole number from 1 to 5.
comment
Optional. The reviewer's comment for the product. HTML is sanitized before it is stored.
The customer must be signed in and must own the review.
{% set reviewId = craft.app.request.getRequiredParam('id') %}
{% set review = craft.productReview.getReviewById(reviewId, null) %}
{% if not review or review.reviewer.id != currentUser.id %}
{% redirect 'shop/customer' %}
{% endif %}
<form id="reviewForm" method="post">
{{ csrfInput() }}
{{ actionInput('product-review/review/save') }}
{{ redirectInput('/shop/customer/review-history') }}
<input type="hidden" name="id" value="{{review.id}}"/>
<div class="rating">
<!-- Notice that the stars are in reverse order -->
<input type="radio" id="star5" name="rating" value="5">
<label for="star5">★</label>
<input type="radio" id="star4" name="rating" value="4">
<label for="star4">★</label>
<input type="radio" id="star3" name="rating" value="3">
<label for="star3">★</label>
<input type="radio" id="star2" name="rating" value="2">
<label for="star2">★</label>
<input type="radio" id="star1" name="rating" value="1">
<label for="star1">★</label>
</div>
<div class="comment">
<label for="comment">Tell us more:</label><br>
<textarea id="comment" name="comment"></textarea>
</div>
<button type="submit" class="submit-btn">Submit</button>
</form>Handling the response
Without a redirectInput(), the request comes back to the same page. Show the flash messages so the customer sees what happened.
When validation fails, the submitted review is available as review so you can re-render the form with the customer's input and the messages against each field.
Last updated