• Resolved benz_admin

    (@benz_admin)


    Hi,
    the plugin is really useful and it’s exactly what I’m looking for!
    But I’m not able to redirect user after they insert a reviews…
    I inserted this code on functions.php of my theme:

    
    add_action( 'site-reviews/local/review/create', function( $post_data, $meta ) {
    header('Location: http://www.example.com/');}, 10, 2 );

    What’s wrong?
    Thanks indvanced

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

    (@geminilabs)

    Yes that wouldn’t work. You can’t change the headers if they have already been set. Also since submission is done via ajax, you won’t be able to perform a redirect via a hook.

    Let me look into it…

    Plugin Author Gemini Labs

    (@geminilabs)

    @benz_admin I have just released v2.2.2

    This release triggers a javascript event after a form has been submitted via ajax and has returned a response, and it also allows you to disable ajax by adding a “no-ajax” class to a form in the shortcode or widget.

    So now you have two options:

    1. Disable ajax on the submission form (i.e. [site_reviews_form id="j29vgthp" class="no-ajax"]), then use the new site-reviews/local/review/submitted hook to trigger a redirect.

      Of course you will then have to return the success message yourself to the user on the page you redirected them to.

      Here is an example of using the hook:

      add_action( 'site-reviews/local/review/submitted', function( $message, $request ) {
          if( $request->ajaxRequest )return;
          wp_safe_redirect( 'https://example.com' );
          exit;
      }, 10, 2 );

      It’s worth noting that if you disable ajax and are using the reCAPTCHA option, the reCAPTCHA will no longer work. I’ll probably add a no-js reCAPTCHA fallback in a later version.

    2. Use the new JS event to redirect to a new page.

      Here is an example of using the JS event:

      document.addEventListener( 'site-reviews/after/submission', function( ev ) {
          if( ev.detail.errors !== false )return;
          window.location = "https://example.com";    
      });
    petschko

    (@petschko)

    Thanks for this, this helps! It there a documentation what can be inside the “ev” var?

    Plugin Author Gemini Labs

    (@geminilabs)

    The ev variable (short for event) is the default Javascript event object that is passed whenever an event is triggered which contains information about the event.

    The only parameter in the ev object that is important in this custom event is the ev.detail parameter. This contains the following:

    ev.detail.errors = This contains any form errors that were passed. You must check that this is false (ev.detail.errors === false) before any redirection takes place.

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

    ev.detail.form = This contains the HTMLFormElement of the review submission form.

    petschko

    (@petschko)

    Thanks for the very fast reply! That was what I’m looking for =)

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘Redirect user after review’ is closed to new replies.