• Resolved jonathangallo

    (@jonathangallo)


    Hi,

    I want to restrict logged in users to vote multiple times and added this code snippet Prevent multiple submissions by email address but it doesn’t work. I can still vote multiple times. The other code snippet Prevent multiple submissions by IP address worked fine but I need to restrict by email address.

    Another thing, this is validated as soon as you click on “Submit”. Is there a way to validate this on page load, add a custom error message and hide the form? So basically if I load the page, it should hide the entire form and just display the text “You have already submitted a review”

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

    (@geminilabs)

    1. The Prevent multiple submissions by email address snippet will only work if you are assigning your reviews to a page (using the “assign_to” option in the [site_reviews_form] shortcode) AND you are using the email field in the form.

    If you are not assigning reviews, you will need to remove the following code from the snippet:

    ) || empty( $request['assign_to']
    

    and

    ['key' => 'assigned_to', 'value' => $request['assign_to']],
    

    2. For this you have two options. The simplest is to redirect the page after the review has been submitted. Please see the Site Reviews > Documentation > FAQ” page for instructions on how to do this.

    If you would prefer not to redirect the page, then the other option is to add the following custom CSS and Javascript to your website:

    The custom CSS

    .glsr-form {
      transition: max-height 0.4s, opacity 0.4s;
      opacity: 1;
    }
    .glsr-hide-form {
      max-height: 0 !important;
      opacity: 0;
      overflow: hidden;
    }

    The custom Javascript

    document.addEventListener('site-reviews/after/submission', function (ev) {
        if (false !== ev.detail.errors) return;
        ev.detail.form.classList.add('glsr-hide-form');
        ev.detail.form.insertAdjacentHTML('afterend', '<p>' + ev.detail.message + '</p>');
    });

    What this does is hides the submission form (slide-up animation) once a review has been successfully submitted and shows the success message in its place.

    3. If you are only allowing registered users to submit reviews and you want to restrict them to only one review each and hide the form if they have already submitted a review, please see: https://pastebin.com/vWhsaT7Z

    • This reply was modified 5 years, 3 months ago by Gemini Labs.
    Thread Starter jonathangallo

    (@jonathangallo)

    Thank you for the different solutions.

    I tried with the last one (3), but I was still able to vote multiple times (normal user). And I am assigning the review to the current page. What I want to accomplish in this website is that every logged in user only can vote once for each page, I guess the code snippet above does this right? It’s just me who doesn’t make it work somehow. Now that I think about it, you can actually change email address, could you somehow look at the user ID instead? I want it to be unique.

    Regarding the second one, I like the opportunity to hide the form when you submit, but is there any code snippet to hide it when I refresh or re-visit the page again (in page load)? Instead of displaying the message after I click on Submit button?

    Plugin Author Gemini Labs

    (@geminilabs)

    Please look at step 3, I suggest you use that together with step 2.

    Thread Starter jonathangallo

    (@jonathangallo)

    That was actually the last thing I tried. I submit a review, the form disappears and the success message is showing up. I refresh the page and submit a review again on the same page and same thing happens and I can see the second review in admin panel. Is there a way I can debug the PHP-code?

    Plugin Author Gemini Labs

    (@geminilabs)

    The code from step 3 will only work if the user is not an admin.

    Thread Starter jonathangallo

    (@jonathangallo)

    Exactly, I used a normal user to try this. Is the code from step 3 preventing multiple reviews from a user? I can’t find such a error message like in the code that looks for email/ip address.

    Plugin Author Gemini Labs

    (@geminilabs)

    Oh…sorry I just realised that step 3 will only work in the unreleased v4.0

    Will update this post with a solution in a few hours.

    Thread Starter jonathangallo

    (@jonathangallo)

    Thank you for the quick feedback! ??

    Plugin Author Gemini Labs

    (@geminilabs)

    Thread Starter jonathangallo

    (@jonathangallo)

    Thank you, but still same as before ?? I can submit multiple reviews with a non-admin account

    Plugin Author Gemini Labs

    (@geminilabs)

    Ah, please see the updated code in the link above.

    Specifically, change this line (which allows 1-2 reviews):

    return count($reviews) > 1
    

    To this (which only allows 1 review):

    return count($reviews)
    

    Tested and working.

    Thread Starter jonathangallo

    (@jonathangallo)

    Thank you!

    I updated the code and could submit more than once. But then, I approved one of the reviews and the form was hidden with the message “Thank you for your review” the next time I loaded the page. This is the correct behaviour right?

    Sorry if I’m annoying with all my question, but do you think I can have this functionality even if a reviews isn’t approved yet? So now for example I have 5 reviews from this user, where one of them is approved, which means he can’t submit again.

    Plugin Author Gemini Labs

    (@geminilabs)

    Yes, that is correct behaviour. You can always change the message in the hook if you like.

    To check both unapproved and approved reviews, add this to the site_reviews_add_author_to_review_query function (code updated in link above):

    $query->set('post_status', ['pending', 'publish']);
    
    • This reply was modified 5 years, 3 months ago by Gemini Labs.
    • This reply was modified 5 years, 3 months ago by Gemini Labs.
    Thread Starter jonathangallo

    (@jonathangallo)

    The code works perfect, thank you again!

    Yes I saw the message in the hook, changed it to Swedish. Now I will try my noob PHP skills (I’m a C#/JavaScript guy) to detect the current language so it will translate the message in the hook into English. Maybe I can use/extend the existing code snippet? ??

    Thread Starter jonathangallo

    (@jonathangallo)

    I figured it out regarding language detection and display message, thanks anyway! This will help me incredibly much!

    I will look further in the forum if I find any function where you have the chance to change your existing review (stars).

    • This reply was modified 5 years, 3 months ago by jonathangallo.
Viewing 15 replies - 1 through 15 (of 20 total)
  • The topic ‘Prevent multiple submissions by email address not working’ is closed to new replies.