Prepopulating registration form with email

Created on 4 October 2023, about 1 year ago
Updated 10 October 2023, about 1 year ago

Have D7 with Login Toboggan and Profile2 Registration Path and tried to populate email field unsuccessfully.
Decided to use workaround inside logintoboggan.module:
Find this code:

      // Weight things properly so that the order is name, mail, conf_mail.
      $form['account']['name']['#weight'] = -30;
      $form['account']['mail']['#weight'] = -29;
    }

and replace with:

      // Weight things properly so that the order is name, mail, conf_mail.
      $form['account']['name']['#weight'] = -30;
      $form['account']['mail']['#weight'] = -29;
	  
		// parse query params to prepopulate email fields
		$url = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
		$url_components = parse_url($url);
		if (!empty($url_components['query'])){
			parse_str($url_components['query'], $params);
		}
		$emailvalue = isset($params['email']) ? $params['email'] : "";
		if ($emailvalue != "") {
			$form['account']['mail']['#value'] = $emailvalue;
			$form['account']['conf_mail']['#value'] = $emailvalue;
		}	  
    }

Usage: https://www.web.site/user/register?email=a@b.ca
Hope it would be helpful for someone. Thank you!

🐛 Bug report
Status

Active

Version

2.0

Component

Code

Created by

🇨🇦Canada gennadiy

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024