Support » Plugin: Site Reviews » Showing message after submitted review

  • Resolved pnikolova

    (@pnikolova)


    This will probably be a more complicated question. I haven’t worked with PHP in a while, and I don’t want to touch any of the files to mess it up. I have added the code for the form to disappear once it is submitted.

    There are 2 scenarios:

    1. When a user submits a review the form hides and a message goes in its place or shows up. Here it will thank them for their review and asks if they don’t mind sharing it on Google too.

    2. ^ + Somehow to copy over the text they submitted or show them their summary so they can just copy and paste it over into Google.

    I tried adding

    /**
     * Runs after a review has been submitted in Site Reviews.
     * Paste this in your active theme's functions.php file.
     * @param \GeminiLabs\SiteReviews\Review $review
     * @param \GeminiLabs\SiteReviews\Commands\CreateReview $request
     * @return void
     */
    add_action('site-reviews/review/created', function ($review, $request) {
        // do something here.
    }, 10, 2);

    but I couldn’t figure out how to write the function or what I should even do. If you have any tips, I appreciate it in advance.

    The page I need help with: [log in to see the link]

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Gemini Labs

    (@geminilabs)

    @pnikolova Unfortunately it is currently not possible to do this as Site Reviews does not return the created review once it has been submitted.

    If you can wait a couple of weeks, Site Reviews v5.0 is on track to be released in early June and will allow you to do this with a code snippet.

    Thread Starter pnikolova

    (@pnikolova)

    That’s fantastic! I look forward to the release! https://imgaz3.staticbg.com/thumb/large/oaupload/banggood/images/C0/D5/b5ba7a1b-8c5e-4dea-b975-8b0a5767d47c.jpg

    When I try to echo ‘Thank you!’ after it is submitted, instead of the form hiding and ‘Thank you!’ appearing, the form is submitted in the backend but gets stuck on loading on the front end. Do you have any ideas?

    Plugin Author Gemini Labs

    (@geminilabs)

    To hide the submission form after a submission, you can use the site-reviews/after/submission custom Javascript event, for example (here is some JavaScript code):

    document.addEventListener('site-reviews/after/submission', function (event) {
        if (event.detail.errors !== false) return;
        // The review has been submitted successfully so you can now 
        // manually hide the submission form and show the success message.
    });
    

    The important property in the event variable in this custom event is the event.detail property. This object contains the following properties:

    event.detail.errors = This contains any form errors that were passed. You must check that this is false (event.detail.errors === false) before any redirection or “on success” logic takes place.

    event.detail.message = This contains either the success message or the error message for the form.

    event.detail.form = This contains the HTMLFormElement of the review submission form. If you want to hide the form after submission, you can use this as the target.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Showing message after submitted review’ is closed to new replies.