Since the page is being loaded with a URL variable as the trigger, you will need to modify the action of the registration form so that it passes the URL variable on post.
change the action:
action="<?php echo (htmlentities($_SERVER["PHP_SELF"], ENT_QUOTES)); ?>"
to:
action="<?php echo (htmlentities($_SERVER["PHP_SELF"], ENT_QUOTES)); ?><?php echo (isset($_SERVER["QUERY_STRING"]) && $_SERVER["QUERY_STRING"] != "")?"?".htmlentities($_SERVER["QUERY_STRING"], ENT_QUOTES):""; ?>"