Title: Variable redirect on User Registration
Last modified: February 23, 2023

---

# Variable redirect on User Registration

 *  Resolved [Mark T](https://wordpress.org/support/users/markascendglobal/)
 * (@markascendglobal)
 * [3 years, 3 months ago](https://wordpress.org/support/topic/variable-redirect-on-user-registration/)
 * Hey,
 * So, I have a Forminator regsitration form that I want to change the redirect 
   URL of, depending on the URL variable
 * I copied and changed [this code](https://wpmudev.com/forums/topic/forminator-pro-forminator-capability/#post-3898135)
   thinking it would work:
 *     ```wp-block-code
       <?php
       /**
        * Plugin Name: [Forminator] - Custom Form Redirect
        * Plugin URI: https://wpmudev.com/
        * Description: Adds custom redirect to Forms based on submitted data
        * Task: SLS-183
        * Version: 1.0.0
        * Author: Panos Lyrakis @ WPMUDEV
        * Author URI: https://wpmudev.com/
        * License: GPLv2 or later
        */
       if ( ! defined( 'ABSPATH' ) ) { 
       	exit; 
       } 
       if ( defined( 'WP_CLI' ) && WP_CLI ) { 
       	return; 
       }
       if ( ! class_exists( 'WPMUDEV_Forminator_CustomForm_Redirect' ) ) {
           class WPMUDEV_Forminator_CustomForm_Redirect {
   
           	private $form_id = 380;
   
               private static $_instance = null;
   
               public static function get_instance() {
                   if( is_null( self::$_instance ) ){
                       self::$_instance = new WPMUDEV_Forminator_CustomForm_Redirect();
                   }
                   return self::$_instance;
               }
               private function __construct() {
               	add_filter( 'forminator_custom_form_submit_response', array( $this, 'handle_response' ), 20, 2 );
               	add_filter( 'forminator_custom_form_ajax_submit_response', array( $this, 'handle_response' ), 20, 2 );
               }
               public function handle_response( $response, $form_id ) {
               	if ( ! $this->is_valid_form( $form_id ) ) {
               		return $response;
               	}
                   if( isset( $response['url'] ) ){
                       $response['url'] = $this->calc_url( $response['url'] );
                   }
               	return $response;
               }
               private function calc_url( $redirect_url ) {
   
               	$new_url = get_bloginfo('url').'/checkout';
   
               	if(isset($_GET['redirect_to']) && $_GET['redirect_to'] == $new_url) {
       				$redirect_url = esc_url($new_url);
               	}
   
                   return $redirect_url;
   
               }
               private function is_valid_form( $form_id ) {
               	return (int) $form_id === $this->form_id;
               }
           }
       	if ( ! function_exists( 'wpmudev_forminator_customform_redirect' ) ) {
           	function wpmudev_forminator_customform_redirect(){    		
           		return WPMUDEV_Forminator_CustomForm_Redirect::get_instance();
           	};
           	add_action( 'plugins_loaded', 'wpmudev_forminator_customform_redirect', 99 );
           }
       }
       ```
   
 * The bit I edited is the `calc_url()` function, as that’s the bit in the original
   code that did the redirect URL change (I think)
 * The login/reg page has the URL variable `?redirect_to=http://mydomainnamehere.
   com/checkout` on the end which is needed for something else and can’t be removed
 * Basically, I want the form with `ID = 380` to redirect to that URL variable, 
   but ONLY if it is present (hence the if statement in my calc_url() change above
 * Can anyone see why this isn’t working?

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

 *  Plugin Support [Nebu John – WPMU DEV Support](https://wordpress.org/support/users/wpmudevsupport14/)
 * (@wpmudevsupport14)
 * [3 years, 3 months ago](https://wordpress.org/support/topic/variable-redirect-on-user-registration/#post-16504675)
 * Hi [@markascendglobal](https://wordpress.org/support/users/markascendglobal/),
 * Trust you are doing good and thank you for reaching out to us.
 * The ticket that you mentioned is a bit old and as we have released many updates
   since then, the code might not work with the latest version of the plugin.
 * Could you please explain the exact workflow that you are looking forward to?
 * Please also share an export of your registration form so that we can help you
   further. You should share the export of the form using pastebin.com or Google
   Drive. Please find how to export a form in our documentation here: [https://wpmudev.com/docs/wpmu-dev-plugins/forminator/#import-export](https://wpmudev.com/docs/wpmu-dev-plugins/forminator/#import-export)
 * We look forward to hearing back from you.
 * Kind Regards,
   Nebu John
 *  Thread Starter [Mark T](https://wordpress.org/support/users/markascendglobal/)
 * (@markascendglobal)
 * [3 years, 3 months ago](https://wordpress.org/support/topic/variable-redirect-on-user-registration/#post-16505458)
 * Hey
 * So, its a WooCommerce site. I’ve replaced the standard WC register form with 
   a Forminator registration form for multiple reasons.
 * This is how the site currently works:
    - The site is set so you cannot buy anything without being a registered user
    - When you get to the checkout page, if you’re not logged in, WooCommerce redirects
      you to the standard login page
    - You either login to an account or register for a new one
    - The login form redirects you back to the checkout (custom code to bypass logging
      in to the account dashboard, which works fine)
    - As it stands, the register form allows you to register but doesn’t redirect
      back to the checkout like the login form
    - There is a custom `?redirect_to=[URL FOR CHECKOUT]` URL parameter, which is
      part of the login redirect coding I made
 * Basically, I want the register form to redirect you to the checkout like the 
   login form, BUT ONLY if that `?redirect_to=` URL parameter is present (eg, if
   it’s not there, register as normal)
 * Pastebin of form export – [https://pastebin.com/ygUwtsTk](https://pastebin.com/ygUwtsTk)
 * I hope that makes sense
 * Thanks
 *  Plugin Support [Patrick – WPMU DEV Support](https://wordpress.org/support/users/wpmudevsupport12/)
 * (@wpmudevsupport12)
 * [3 years, 3 months ago](https://wordpress.org/support/topic/variable-redirect-on-user-registration/#post-16507900)
 * Hi [@markascendglobal](https://wordpress.org/support/users/markascendglobal/)
 * Thank you for the information.
 * I believe you can do that without any custom coding, Forminator has the hidden
   field and the conditionals after submissions, can you try this form?
 * [https://pastebin.com/kzEL3hLv](https://pastebin.com/kzEL3hLv)
 * I added a hidden field to catch the redirect URL [https://monosnap.com/file/d4ugnIvEUEkWbpDLPlhVCfOGvaerLK](https://monosnap.com/file/d4ugnIvEUEkWbpDLPlhVCfOGvaerLK)
 * Then added the field in the redirect URL [https://monosnap.com/file/k2E5WJmTGkNzUfwMy17OfDg3gBhrp8](https://monosnap.com/file/k2E5WJmTGkNzUfwMy17OfDg3gBhrp8)
   and two conditionals, one to redirect if the field is not null and not redirect
   if the field is null.
 * Best Regards
    Patrick Freitas
 *  Thread Starter [Mark T](https://wordpress.org/support/users/markascendglobal/)
 * (@markascendglobal)
 * [3 years, 3 months ago](https://wordpress.org/support/topic/variable-redirect-on-user-registration/#post-16509342)
 * Hey Patrick
 * I knew it would be something a lot simpler!
 * That’s done the job perfectly, thank you
 * Consider this topic resolved
 * Mark
 *  Plugin Support [Saurabh – WPMU DEV Support](https://wordpress.org/support/users/wpmudev-support7/)
 * (@wpmudev-support7)
 * [3 years, 3 months ago](https://wordpress.org/support/topic/variable-redirect-on-user-registration/#post-16511870)
 * Hi [@markascendglobal](https://wordpress.org/support/users/markascendglobal/)
 * Thanks for confirming this ticket has been solved. If you need help with any 
   additional request feel free to open a new ticket. Our team will be glad to help
 * Kind regards
 * Luis

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

The topic ‘Variable redirect on User Registration’ is closed to new replies.

 * ![](https://ps.w.org/forminator/assets/icon-256x256.gif?rev=3443182)
 * [Forminator Forms – Contact Form, Payment Form & Custom Form Builder](https://wordpress.org/plugins/forminator/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/forminator/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/forminator/)
 * [Active Topics](https://wordpress.org/support/plugin/forminator/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/forminator/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/forminator/reviews/)

## Tags

 * [mu-plugin](https://wordpress.org/support/topic-tag/mu-plugin/)
 * [redirect](https://wordpress.org/support/topic-tag/redirect/)
 * [Registration](https://wordpress.org/support/topic-tag/registration/)
 * [url](https://wordpress.org/support/topic-tag/url/)
 * [variable](https://wordpress.org/support/topic-tag/variable/)

 * 5 replies
 * 4 participants
 * Last reply from: [Saurabh – WPMU DEV Support](https://wordpress.org/support/users/wpmudev-support7/)
 * Last activity: [3 years, 3 months ago](https://wordpress.org/support/topic/variable-redirect-on-user-registration/#post-16511870)
 * Status: resolved