Submitting a review

To submit a review, you can make a post request to product-review/review/save action endpoint.

Params

Param
Description

id

Required. The ID of the review that will be saved.

rating

Required. The rating value for the product.

comment

Optional. The reviewer's comment for the product.

{% 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">&#9733;</label>
        <input type="radio" id="star4" name="rating" value="4">
        <label for="star4">&#9733;</label>
        <input type="radio" id="star3" name="rating" value="3">
        <label for="star3">&#9733;</label>
        <input type="radio" id="star2" name="rating" value="2">
        <label for="star2">&#9733;</label>
        <input type="radio" id="star1" name="rating" value="1">
        <label for="star1">&#9733;</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>

Last updated