At registration time, I want to generate the userid from three fields: custom field Unit Number, first name, and last name.
I’ve been looking at Jason Caldwell’s solution for creating a userid from an email address (http://www.primothemes.com/forums/viewtopic.php?f=36&t=14806&p=33812#p33812), and a modification that is more helpful for me, Raam Dev’s solution to create a userid from the first part of the email address, plus a randomly generated number (http://www.primothemes.com/forums/viewtopic.php?f=4&t=15672&p=49082#p49082). In Raam’s solution, he also hides the userid field, so that the user can not edit it.
BTW, thank you so much Jason and Raam for sharing your code.
My challenge is that I want to hide the userid field, then create a userid from three separate fields. Jason and Raam’s solutions use the keykup event on the email field. But I have three separate fields which must each be entered to create the login value. I tried using the keyup event on the Registration button, but then I have a problem because the userid is still blank, so fails validation.
My jQuery and RegEx skills are weak. I’m trying to .trim, and eventually I need to remove any blanks from within the userid. I would appreciate any coding help you can offer.
Here is as far as I have gotten with my code:
<?php
add_action ("login_head", "s2_customize_login", 1000);
function s2_customize_login ()
{
?>
<script type = "text/javascript">
function getParameterByName(name)
{
name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
var regexS = "[\\?&]" + name + "=([^&#]*)";
var regex = new RegExp(regexS);
var results = regex.exec(window.location.href);
if(results == null)
return "";
else
return decodeURIComponent(results[1].replace(/\+/g, " "));
}
(function ($) /* Wraps this `$ = jQuery` routine. */
{
$.fn.swapWith = function (to) /* Utility extension for jQuery. */
{
return this.each (function ()
{
var $to = $ (to).clone (true), $from = $ (this).clone (true);
$(to).replaceWith ($from), $ (this).replaceWith ($to);
});
};
/**/
$(document).ready (function () /* Handles email-to-username on keyup. */
{
/* If this is the register page, customize it */
if(getParameterByName('action') == 'register')
{
var login = 'input#user_login';
var firstname = 'input#ws-plugin--s2member-custom-reg-field-first-name';
var lastname = 'input#ws-plugin--s2member-custom-reg-field-last-name';
var unitnumber = 'input#ws-plugin--s2member-custom-reg-field-unit-number';
$(login).closest ('p').hide(); // This hides the closest P above the login field,
// which is the p containing the login field.
$ (firstname).keyup (function ()
{ $(login).val ( ($.trim ($ (unitnumber).val )) + "_" +
($.trim ($ (firstname).val )) + "_" + ($.trim ($ (lastname).val )) ) ;
});
}
});
}) (jQuery);
</script>
<?php
}
?>
The code is only using the keyup event of firstname, and as soon as I enter anything in firstname, I get the following, which I don’t know how to interpret:
function (e){var n,r,i,s=this[0];if(!arguments.length){if(s)return n=v.valHooks[s.type]||v.valHooks[s.nodeName.toLowerCase()],n&&"get"in n&&(r=n.get(s,"value"))!==t?r:(r=s.value,typeof r=="string"?r.replace(R,""):r==null?"":r);return}return i=v.isFunction(e),this.each(function(r){var s,o=v(this);if(this.nodeType!==1)return;i?s=e.call(this,r,o.val()):s=e,s==null?s="":typeof s=="number"?s+="":v.isArray(s)&&(s=v.map(s,function(e){return e==null?"":e+""})),n=v.valHooks[this.type]||v.valHooks[this.nodeName.toLowerCase()];if(!n||!("set"in n)||n.set(this,s,"value")===t)this.value=s})}_function (e){var n,r,i,s=this[0];if(!arguments.length){if(s)return n=v.valHooks[s.type]||v.valHooks[s.nodeName.toLowerCase()],n&&"get"in n&&(r=n.get(s,"value"))!==t?r:(r=s.value,typeof r=="string"?r.replace(R,""):r==null?"":r);return}return i=v.isFunction(e),this.each(function(r){var s,o=v(this);if(this.nodeType!==1)return;i?s=e.call(this,r,o.val()):s=e,s==null?s="":typeof s=="number"?s+="":v.isArray(s)&&(s=v.map(s,function(e){return e==null?"":e+""})),n=v.valHooks[this.type]||v.valHooks[this.nodeName.toLowerCase()];if(!n||!("set"in n)||n.set(this,s,"value")===t)this.value=s})}_function (e){var n,r,i,s=this[0];if(!arguments.length){if(s)return n=v.valHooks[s.type]||v.valHooks[s.nodeName.toLowerCase()],n&&"get"in n&&(r=n.get(s,"value"))!==t?r:(r=s.value,typeof r=="string"?r.replace(R,""):r==null?"":r);return}return i=v.isFunction(e),this.each(function(r){var s,o=v(this);if(this.nodeType!==1)return;i?s=e.call(this,r,o.val()):s=e,s==null?s="":typeof s=="number"?s+="":v.isArray(s)&&(s=v.map(s,function(e){return e==null?"":e+""})),n=v.valHooks[this.type]||v.valHooks[this.nodeName.toLowerCase()];if(!n||!("set"in n)||n.set(this,s,"value")===t)this.value=s})}
I humbly ask for help.