Registration fields prefilled with URL parameters
-
Hey everyone,
I’d like to invite some users via email to register and would like to prefill the user registration fields, such as A.) username and B.) email.
Unfortunately it is not working. Can someone guide me in the right direction?
I’ve already tried the following…In functions.php I’m checking if we’re on Login/Register Page
function is_wplogin(){ $ABSPATH_MY = str_replace(array('\\','/'), DIRECTORY_SEPARATOR, ABSPATH); return ((in_array($ABSPATH_MY.'wp-login.php', get_included_files()) || in_array($ABSPATH_MY.'wp-register.php', get_included_files()) ) || (isset($_GLOBALS['pagenow']) && $GLOBALS['pagenow'] === 'wp-login.php') || $_SERVER['PHP_SELF']== '/wp-login.php'); } function prefillercheck(){ if( is_wplogin() ){ wp_enqueue_script('prefiller', 'https://mydomain.com/prefiller.js',); } } add_action('login_enqueue_scripts', 'is_wplogin'); add_action('login_enqueue_scripts', 'prefillercheck');
So far so good…
The following Javascript code of “prefiller.js” also seems to be loading on Login/Register Page.
But it is not populating the fields (‘user_login’ and ‘user_email’). :/<script type="text/javascript"> var getUrlParameter = function getUrlParameter(sParam) { var sPageURL = decodeURIComponent(window.location.search.substring(1)), sURLVariables = sPageURL.split('&'), sParameterName, i; for (i = 0; i < sURLVariables.length; i++) { sParameterName = sURLVariables[i].split('='); if (sParameterName[0] === sParam) { return sParameterName[1] === undefined ? true : sParameterName[1]; } } }; var VARIABLE = getUrlParameter('PARAMETER'); if (VARIABLE != null) { document.getElementById('INPUT-FIELD-ID').value = VARIABLE; } </script>
Code Source:
From this tutorial https://www.youtube.com/watch?v=2nUOQl4E9HY
Code source (js script): https://wplearninglab.com/contact-form-7-get-value-from-url/
Code source (Check is_wplogin): https://wordpress.stackexchange.com/a/237285Can someone tell me what I am missing? Pleeeeeease! Thank you!
- The topic ‘Registration fields prefilled with URL parameters’ is closed to new replies.