Redirect to the referrer URL with CRED

Let’s assume you have a CRED Form on a Post or Page, which is appearing on several different Posts or pages (via content template as for example), and you want to be redirected to the Page/post where the CRED form is present, after submitting it.

One possibility is to “Keep display this form”, but that will also keep display the success messages and so on

Therefore you need a dynamic redirect to the Referrer URL.

This can be done with the WordPress function wp_get_referer()

Example:

add_filter('cred_success_redirect', 'custom_redirect',10,3);

function custom_redirect($url, $post_id, $form_data) {
  //Only if the Form is ID 54
  if ($form_data['id']==54) {

   //Populate a variable $redirect with the referrer URL
    //see https://codex.wordpress.org/Function_Reference/wp_get_referer
    $redirect = wp_get_referer();
    if ($redirect) {
      return $redirect;
    }
    else {
      die;
    }
  }
}

 

Ticket:
https://wp-types.com/forums/topic/cred-form-back-1-page-on-submition/

Let us know if this snippet is not working for you:

This snippet doesn’t work
0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments