User registration: use information from email address (add-on existing or to be created?)

I'd like to aid user self-registration on our site, using the information from the email address incrementally:

  • The first information to be entered is the email address, which is often of the form firstname.lastname@domain.
  • When the email address input field is left, and the username field is empty, the before-hostname-part is used (or the whole email address, perhaps).
  • When the username field is left, and the firstname field is empty, a firstname is guessed (usually the part before the dot).
  • When the firstname field is left, and the lastname field is empty, a lastname is guessed (e.g. the not yet used part of the username).

That way, many users could simply enter their email address, and then simply skip through the fields, using the tab key; the form will incrementally be filled, while modifications are possilbe at all times.
I contributed such a logic (a little bit simpler, perhaps) years ago to the (now historic) Python bugtracker (or, more precisely, to the Roundup bugtracker), and it seems to have been online untill that tracker was migrated to Github.

Do we have an add-on to do this already, or is it perhaps part of any newer Plone version?

I would add a little javascript. It should not be difficult to split the names (you probably want to make a check, too and captialize first letter – .toUpperCase(), maybe ).

Probably something like

email = 'john.doe@email.com';
result = email.split('@')[0];

console.log(result); // 👉️ "john.doe"

firstname = email.split('.')[0];

Yes, of course; the question is: Do we have some little extension already, or should I create it?

There is more to do for the script:

  • Find the form to be operated on, and hook to it the events delegation. That way it would be possible to operate e.g. on every form which contains an email and at least one *name field without the need to include the script individually.
  • For each name-related input field in question, take the value into account whenever it is left.
  • Do some considerably generic logic for the educated guesswork.

Thus, IMO this is worth a little extension package.

From what I understand, the package would basically just contain one javascript. If so, a package might be 'overcomplicating it' instead of just adding it to the theme ?

Does not a lot of browsers autofill these fields anyway?

About 'finding the name field': I think you can just run it on every 'email field' and find parent 'form' and child 'name' and set their content if field is empty.

Of course, if you plan to reuse this, you could add a control panel with options about what to do when name includes more than '2 names', middle and other names ) and enable / disable this logic in the control panel.

Update: In case it should be of interest: https://codepen.io/espenmn/pen/RwQgGpY

1 Like

Seems a good case for a new mockup pattern. It is similar to validation pattern:
http://plone.github.io/mockup/dev/#pattern. Also
https://github.com/plone/mockup/tree/master/src/pat/formautofocus works on inputs.

They are already used on the /@@new-user form.

Yes, it would. Nothing wrong about that, IMO: I'm currently still (sign ...) on Plone 4. If the functionality can be implemented in some better way in Plone 5+, I'll happily drop my package.
Or update it as needed.

Perhaps I'll end up with "simply adding it to the theme". But the "theme" I work with is something I inherited, and a lot of stuff had once been copied from whatever sources (e.g. old versions of DataTables), so I try to weed out that stuff and use packages whenever possible.

Yes, they do; and if they do so, that values would still be used.
But they might not (e.g. because expecting slightly different field names).
Or peoply might have suppressed the functionality somehow, for privacy considerations.

Thanks for the mockup.
Your code takes the email value and autofills the three remaining fields.
My idea is to do this step by step only; and of course never ever change values entered by the user (unless perhaps explicitly requested to do so).

I just made that as a test, so I did not think about 'what logic would be best'. Anyway: You can always run some other code after leaving 'another input' (or enterin on) .

I made a check for one of the fields (so it will only add entry if the field is empty. Use that on all and you will 'never change values entered by user'

Yes, thank you. Please don't feel compelled to write my extension :slightly_smiling_face: